我是否应该通过执行以下命令找到主键为ObjectId的文档:
this._db
.collection('users')
.find({ _id: 'aaaaa0000000000000000000' })
.toArray();或
this._db
.collection('users')
.find({ _id: ObjectId('aaaaa0000000000000000000') })
.toArray();发布于 2017-08-25 01:30:18
只有第二个可以工作:
this._db
.collection('users')
.find({ _id: ObjectId('aaaaa0000000000000000000') })
.toArray();您的问题没有标记为Mongoose,如果需要,Mongoose提供了通过字符串进行查询的能力。Pure Mongo要求你使用ObjectId。
https://stackoverflow.com/questions/45866776
复制相似问题