[英]find the document which equals any one of the array element query with a non array field
mongo db schema variable mongo db 模式变量
status:{
type: Number,
enum: [0,1,2,3,4,5], //0-NOT ACCEPTED,1-COMPLETED,2-PENDING
default: 0
}
status stored in db like 0 or 1 or 2. status search with user selection is array of datas like状态存储在数据库中,如 0 或 1 或 2。用户选择的状态搜索是数据数组,如
status: {1,2}
how to get the documents which has any one the of the array element.如何获取包含任何一个数组元素的文档。 I can't do a static search because array size can change every time
我无法进行静态搜索,因为数组大小每次都会改变
// if(status){
// query = {
// ...query,
// "status": status
// }
// }
console.log(body_status);
if(body_status){
query = {
...query,
"status": {"$in":body_status}
}
}
this works for me.这对我有用。
I don't know if I've understand the question but I think you want something like this:我不知道我是否理解这个问题,但我认为你想要这样的东西:
db.collection.find({
"status": {
"$in": [
1,
2,
4
]
}
})
Please check if it works as expected or not and in this case update the question with more information.请检查它是否按预期工作,在这种情况下,请使用更多信息更新问题。
Or maybe you want something like this :或者,也许你想要的东西,像这样:
db.collection.find({
"status": 1
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.