- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我似乎无法解决这个问题。当点击此 URL http://localhost:5000/sysaccess/test 时,我收到此错误消息。
( Node :34256)UnhandledPromiseRejectionWarning:未处理的 promise 拒绝(拒绝ID:1):CastError:模型“sysaccess”的路径“_id”处的值“test”转换为ObjectId失败( Node :34256)[DEP0018] DeprecationWarning:未处理的 promise 拒绝已被弃用。将来,未处理的 Promise 拒绝将会以非零退出代码终止 Node.js 进程。
在我的 sysaccess.js 路由中,我有这个:
const express = require('express');
const csv = require('csv-express');
const mongoose = require('mongoose');
const router = express.Router();
const {ensureAuthenticated} = require('../helpers/auth');
const Sysaccess = mongoose.model('sysaccess');
const Vendor = mongoose.model('vendor');
router.get('/test', (req, res) => {
res.send('ok');
});
我已将 sysaccess.js 路由与供应商.js 路由进行了比较,一切看起来都正常。我在vendor.js中有十几条路线,没有任何问题。我花了很多时间谷歌这个但没有找到任何东西。有人可以告诉我我在这里缺少什么吗?预先感谢您!
最佳答案
您的 sysaccess.js
路由器中的中间件顺序错误。
例如:
// "GET /sysaccess/test" will be processed by this middleware
router.get('/:id', (req, res) => {
let id = req.params.id; // id = "test"
Foo.findById(id).exec().then(() => {}); // This line will throw an error because "test" is not a valid "ObjectId"
});
router.get('/test', (req, res) => {
// ...
});
<小时/>
解决方案 1:使那些更具体的中间件位于那些更通用的中间件之前。
例如:
router.get('/test', (req, res) => {
// ...
});
router.get('/:id', (req, res) => {
// ...
});
解决方案2:使用next
将请求传递给下一个中间件
例如:
router.get('/:id', (req, res, next) => {
let id = req.params.id;
if (id === 'test') { // This is "GET /sysaccess/test"
return next(); // Pass this request to the next matched middleware
}
// ...
});
router.get('/test', (req, res) => {
// ...
});
关于node.js - Actor 错误: Cast to ObjectId failed for value "route-name" at path "_id" for model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49700471/
这个问题已经有答案了: node.js mongodb .. the (immutable) field '_id' was found to have been altered (5 个回答) 已关
db.books.update({bookId:"123461"},{$set:{"bookPrice":"6.23"}}) 我收到错误: update { q: { bookId: "1234
使用典型的 _id 列并连接表并在创建游标时选择所有列,将导致包含多个 _id 列的游标。 要访问特定的 _id 列,则需要使用实际偏移量,而不是列名。 使用硬编码的偏移量可能会有问题,它使代码更难阅
我使用 ASP .NET MVC4 WebAPI 并且我有一些类(class) public class Recipe { [BsonId] [BsonRepresentation(B
我正在尝试为 MongoDB 中的 _id 字段使用 UUID。 我有一个包装器结构来保存我的记录,如下所示: type mongoWrapper struct { ID uuid.
在 CodeIgniter 的 MongoDB 中进行更新时,出现以下错误: Type: MongoWriteConcernException Message: localhost:27017: Af
我想启动分片。如您所知,分片键非常重要。我发现,MongoDB doesn't ensure unique _id field values when using a shard key other
当我在ES 6.3.2上使用以下内容进行搜索时,没有问题: {“查询”:{“match_phrase_prefix”:{“_ id”:“ZX-bLmsBFOiwdS-Iwr24”}}} 但是,当我在E
我想运行以下查询: Group.find({program: {$in: [...]}}).lean().select('_id') 然后不得到回复: [{_id: ...}, {_id: ...},
我已将我的 ID 重命名为 _id,但仍然得到列“_id”不存在 ...我错过了什么吗? MyDatabaseelper.java public class MyDatabaseHelper exte
所以当我使用 int location = cursor.getColumnIndex(_ID) 它总是返回零,尽管 long locationId = cursor.getlong(getColum
我有一个看起来像这样的路径 path: '/speakers/singleDetails/:_id' 和一个具有这样的字段的架构 speakerId: { type: String,
userSchema={ username: { type: String, required: true, unique: true }, password: {
我正在尝试使用 updateOne 方法更新文档: UpdateResult r = coll.updateOne( eq("_id", id), this.getMapper().m
例如: 我有一个收藏“故事”其中每个文档的形式为: { '_id': 'story': } 现在每当我有一个故事时,如果它已经存在于“故事”中,我想要它的“_id”,否则插入一个带有“故事
这是我的 users.js(routes) for(var zz =0;zz < d.length; zz++){ temp
我在 Nodejs 中有一个数组,其中包含需要检索的 mongoDB 文档的 document _id 值。因此,我需要以这样的方式查询 mongoDB,使其返回 _id 值与我想要传入查询的数组中至
正如您在 NodeJS 代码中看到的那样,我正在从 URL 中提供的 Postman token 中获取用户,但我正在努力从给定的 token 号中取回 _id 属性。我想要的是decoded._id
我是 Android 新手。我有一个 SQLite 后端,其中每一行都是唯一的(想想一个人)。然后,我在每个人的 ListView 中显示这些数据。单击 ListView 项时,它将转到 subvie
他们是否都引用了联系人的同一个唯一 contactId? 最佳答案 他们应该这样做,但不能保证联系人是否已同步或聚合。您可能想尝试使用 LOOKUP_KEY相反。 关于Android dev : Ph
我是一名优秀的程序员,十分优秀!