'MongoDB search query with specific id
{ _id: ObjectId("62541083e601e0bddf0e1681"),
name: 'Monitioir',
brand: 'sonic',
price: 70000,
category: 'monitor',
user_id: '62541073e601e0bddf0e167d',
__v: 0 }
{ _id: ObjectId("62540d527fe95cb11db5ad86"),
name: 'Laptop 8 GB Ram',
brand: 'DEL',
price: 60000,
category: 'laptop',
user_id: '62517edb7fc85c423a5b12c3',
__v: 0 }
I have a 2 products in my collection inserted by 2 different users in front-end I am creating a search bar where user can search only the products added by him only the search api that I have created is also returning the products added by the other users also my query is
db.products.find({$or:[{name:{$regex:"o"}}]})
after executing this query both users products are coming i want only of specific user.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
