[英]How to get all users except select user from mongodb using mongoose
I'm trying to get the users from the mongo database
using mongoose
. 我正在尝试使用
mongoose
从mongo database
获取用户。 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?
我怎样才能做到这一点?
you can try to use the query below:- 您可以尝试使用以下查询:-
UsersModel.find({ email: { $ne: 'testemail@email.com' } })
Let me know if it helps. 让我知道是否有帮助。 Thanks
谢谢
UsersModel.find({ email: { $ne: 'testemail@email.com' } })
有关更多信息,请访问此网址
https://docs.mongodb.com/manual/reference/operator/query/ne/
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"] } } )
Here User is the user model. 这里的用户是用户模型。 we will get all users except the current user
我们将获得除当前用户外的所有用户
const users = User.find({ _id: { $ne: user._id } })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.