For example
In the score collection
{
"_id"—ObjectId("50f5379785ac77daf3dd4bfd"),
"user": {
"$ref": "collection_user",
"$id"—ObjectId("50f5370e85ac77daf3dd4bfb")
},
"score"—100
}
{
"_id"—ObjectId("50f5370e85ac77daf3dd4bfb"),
"name": "User1",
"No": 1111
}
When there is data like , we would like to use the user collection in the core collection as an external merge to specify search criteria or sort criteria in name.
If it's mongoDB 3.6 or higher, I feel like I can go there with lookup, but if it's 2.6 or higher, is there any way to achieve it?
mongodb
Database server side failed before MongoDB v3.2.Application-side coupling is required.
One application pseudocode image:
users_rs=db.user.find({name:xxxxxx})
user_id_list = [ ]
for doc in users_rs:
user_id_list.append(doc._id)
scores_rs=db.scores.find({"user.$id":{$in:user_id_list}})
by merging //scores and users data
// Then sort
© 2024 OneMinuteCode. All rights reserved.