Answer the question
In order to leave comments, you need to log in
Mongodb: how to make a select query by checking the internal properties of the model through ObjectID?
The product database (db.products) contains model in ObjectId
```
[{
"_id" : ObjectId("1a736ab23b084b1bb18f5d41"),
"model" : ObjectId("1a736ab13b084b1bb18f5d31")
},
{
...
}
]
```
Resolved model looks like this
{
"_id" : ObjectId("1a736ab13b084b1bb18f5d31"),
"value": 42
}
How to write a query to display all products with model value > 50?
Answer the question
In order to leave comments, you need to log in
db.products.aggregate([
{"$match": {"$modelData.value": {"$gt": 50}} },
{$lookup: {from: "model",localField: "model",foreignField: "_id",as: "modelData"}}
// , {"$exists": "$modelData"} возможно нужно будет указать
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question