I have a MongoDB collection with records having a \"name\"
field, I am trying to perform a find query where the name field appears twice in the query. I want to exc
Your query JSON object contains name
field two times, and it breaks the query. Pay attention to the $and mongo query operator. There are two ways to construct correct query:
1) db.users.find({ $and: [{ name: { $nin: [current_user] } }, { name: { $regex: new RegExp(/query/) } }] })
2) db.users.find({ name: { $nin: [current_user], $regex: new RegExp(/query/) } })
Also, if you exclude only one user, you can use $ne operator instead of $nin
.