在带有 NodeJS 的 Mongoose 中使用带有数组的 findOne
Using findOne with Arrays in Mongoose with NodeJS
在带有 Mongoose 的 NodeJS 中,我如何使用 findOne()
在 数组中搜索某些内容 ?我想在我的 sessionCollection
-Model 的 users
数组中搜索类似 626ead978edc5f2a3f7ca924
的内容。
我的数据库看起来像这样:Database Picture
它将像非数组键一样正常工作:
SessionCollection.findOne({users: mongoose.Types.ObjectId("626ead978edc5f2a3f7ca924")})
您可能需要转换为 objectId 以获得所需的结果。
Reference
在带有 Mongoose 的 NodeJS 中,我如何使用 findOne()
在 数组中搜索某些内容 ?我想在我的 sessionCollection
-Model 的 users
数组中搜索类似 626ead978edc5f2a3f7ca924
的内容。
我的数据库看起来像这样:Database Picture
它将像非数组键一样正常工作:
SessionCollection.findOne({users: mongoose.Types.ObjectId("626ead978edc5f2a3f7ca924")})
您可能需要转换为 objectId 以获得所需的结果。 Reference