select * from user where (name=1 or name=2) and (age=1 or age=2)
这样的语句,怎么用mongo写出来?
select * from user where (name=1 or name=2) and (age=1 or age=2)
这样的语句,怎么用mongo写出来?
用这个命令:db.getCollection("users").find({$and:[{ $or:[{name:1},{name:2}]},{$or:[{age:1},{age:2}]}]})
查询的原先数据:
{
"_id" : ObjectId("5e2150154c5b973028752394"),
"name" : 1.0,
"age" : 2.0
}
// ----------------------------------------------
{
"_id" : ObjectId("5e2150214c5b973028752395"),
"name" : 2.0,
"age" : 1.0
}
// ----------------------------------------------
{
"_id" : ObjectId("5e21502c4c5b973028752396"),
"name" : 3.0,
"age" : 1.0
}
// ----------------------------------------------
{
"_id" : ObjectId("5e21503a4c5b973028752397"),
"name" : 1.0,
"age" : 3.0
}
查询得到的结果:
{
"_id" : ObjectId("5e2150154c5b973028752394"),
"name" : 1.0,
"age" : 2.0
}
// ----------------------------------------------
{
"_id" : ObjectId("5e2150214c5b973028752395"),
"name" : 2.0,
"age" : 1.0
}
1 回答1.3k 阅读✓ 已解决
2 回答1.5k 阅读
1 回答1.4k 阅读
1 回答717 阅读
什么情况,都审核一天了,还没有审核完吗?