![](/img/trans.png)
[英]How to skip the 50 records and after that find the matched records in mongodb by using findOne query in node.js
[英]How to conditionally find records from mongodb using node
[
{
name: 'Some one'
rep_id: '101',
user_ids: ['102','103','104']
},
{
name: 'Some one else'
rep_id: '106',
user_ids: ['102','103','104','105']
},
]
我想从mongodb
搜索带有 rep_id 的记录。 如果 rep_id 不匹配,它应该在 user_ids 数组中搜索相同的 id。 如果它也不存在于 user_ids 数组中,它应该跳过该记录。 我能够找到匹配的 rep_id 但如果它不匹配并且它存在于 user_ids 数组中,我该怎么做。 从上面的记录中,如果 rep_id 是101
它应该给我第一条记录,如果 rep_id 是102
它应该给我两条记录,因为102
存在于两个 user_ids 数组中。
即使是解决方案的提示就足够了
使用$or
db.collection.aggregate([
{
"$match": {
"$or": [
{
rep_id: "102"
},
{
user_ids: "102"
}
]
}
}
])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.