I would like to query data from mongodb and filter based on some condition. The idea is let say I would like to receive all items where status is sold
Code looks as below:
db.collection('items').find({ users.name: { $in: ["Tomas","Antti"] } }).toArray(function (err, items) {
console.log(items);
});
and my collection looks like:
{
_id: ObjectId("5c9cddd50e08a84cd3f4cccb"),
item: "Item 1",
users: {
"be81afc": {"name:"John"},
"78sdjh3": {"name:"Antti"},
"78sd78a": {"name:"Antti"},
},
timestamp: 123123123
}
Supposing that I have many documents on items
collection, how to filter items on getting items where the condition is met using where statement. As you can see there is a hash code within users which I dont need to care about, all I need is filter items where users name is equal to for ex Tomas and Antti