1

I'm trying to get the users from the mongo database using mongoose. If i select a user i want to eliminate that user records and get all the remaining users from database. how can i do that?

2
  • which parameter will decide about not selecting the user ? Commented Apr 4, 2018 at 6:44
  • whatever in record like name Commented Apr 4, 2018 at 7:27

4 Answers 4

5

you can try to use the query below:-

    UsersModel.find({ email: { $ne: '[email protected]' } })

Let me know if it helps. Thanks

Sign up to request clarification or add additional context in comments.

Comments

2

Here User is the user model. we will get all users except the current user

 const users = User.find({ _id: { $ne: user._id } })

Comments

1
UsersModel.find({ email: { $ne: '[email protected]' } })

for more follow this url

   https://docs.mongodb.com/manual/reference/operator/query/ne/

Comments

1

Well, if you want to exclude just one user, you can use

db.collection.find( { name: { $ne: "name" } } )

And if you want to exclude more than one records. May be more than one selected records. This is the way to go

db.collection.find( { name: { $nin: ["name1", "name22"] } } )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.