如何在 Mongoose 中执行 id 数组查询? [英] How do I perform an id array query in Mongoose?
本文介绍了如何在 Mongoose 中执行 id 数组查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个名为 User
的模型.我有一个带有对象 ID 的数组.
Let's say I have a model called User
.
I have an array with object Ids.
我想获取与我拥有的 ID 数组相交"的所有用户记录.
I want to get all User records that "intersect" with the array of Ids that I have.
User.find({ records with IDS IN [3225, 623423, 6645345] }, function....
推荐答案
你需要使用 $in 操作符 >
You need to use the $in operator >
https://docs.mongodb.com/manual/reference/operator/query/in/#op._S_in
例如:
Users.find( { "fb" : { id: { $in : arrayOfIds } } }, callback );
这篇关于如何在 Mongoose 中执行 id 数组查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文