I want to combine the result of $in
query with $nin
query and want the final result. So how we can do this using one mongo query? is there is any way to do it?
For e.g., I have the following documents in the user collection:
[{
name:"test",
"uid":123
},{
name:"test1",
"uid":124
},{
name:"test2",
"uid":125
},{
name:"test3",
"uid":126
},{
name:"test3",
"uid":127
}]
and I want the following result:
[{
name:"test2",
"uid":125
},{
name:"test3",
"uid":126
},{
name:"test",
"uid":123
},{
name:"test3",
"uid":127
}]
Basically I want uid:125
and uid:126
on first two position ignore about their sequence and then uid:123
and uid: 127
on 3rd and 4th position ignore about their sequence. So I am doing this by following two query
db.getCollection('user').find({uid:{$in:[125,126]}})
db.getCollection('user').find({uid:{$nin:[125,126]}})
and then I am combining the result but How I can do this in the same query? I have so many documents it is just example so need to combine the result of $in and $nin query
How I can do this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…