'How to query data with and conditions in mongoose
I have a document of transactions where a transaction can be of different shops.
I want to query transactions with certain id in certain date. I have a field for date and id which is a MongoDB id, when I query using
Transaction.find({ $and: [{ date: nepali_date.day, shop_id: user.shop_id }] }).lean()
It returns data of all the transaction with the date given, I don't want that, I want the data of date 14 AND shop id "61f3c70c89e5453d271e0ea7"
but instead it returns:
{
"_id": "61f3c81a1410f50644d981b6",
"year": 2078,
"month": 9,
"date": 14,
"title": "Krus",
"amount": 60,
"type": "income",
"author": "Eclipsu",
"authorID": "61ef7e9565a4a88874937e96",
"shopID": "61f3c70c89e5453d271e0ea7",
"edited": false
},
{
"_id": "61f3c89ce0ea4276ddba693f",
"year": 2078,
"month": 9,
"date": 14,
"title": "RAJ",
"amount": 50,
"type": "income",
"author": "Eclipsu",
"authorID": "61ef7e9565a4a88874937e96",
"shopID": "61ef7ea165a4a88874937e9d",
"edited": false
}```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
