B
B
baskovsky.ru2018-04-23 14:34:25
MongoDB
baskovsky.ru, 2018-04-23 14:34:25

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

1 answer(s)
A
Alexander N++, 2018-04-23
@qertis

db.products.aggregate([
        {"$match":  {"$modelData.value": {"$gt": 50}} },
        {$lookup: {from: "model",localField: "model",foreignField: "_id",as: "modelData"}}
        // , {"$exists": "$modelData"} возможно нужно будет указать 
]);

All this in theory can work
https://docs.mongodb.com/master/reference/operator...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question