[英]How to get all users except select user from mongodb using mongoose
我正在嘗試使用mongoose
從mongo database
獲取用戶。 如果我選擇一個用戶,我想消除該用戶記錄,並從數據庫中獲取所有其他用戶。 我怎樣才能做到這一點?
您可以嘗試使用以下查詢:-
UsersModel.find({ email: { $ne: 'testemail@email.com' } })
讓我知道是否有幫助。 謝謝
UsersModel.find({ email: { $ne: 'testemail@email.com' } })
有關更多信息,請訪問此網址
https://docs.mongodb.com/manual/reference/operator/query/ne/
好吧,如果您只想排除一個用戶,則可以使用
db.collection.find( { name: { $ne: "name" } } )
如果要排除多個記錄。 可能是多個選定的記錄。 這是要走的路
db.collection.find( { name: { $nin: ["name1", "name22"] } } )
這里的用戶是用戶模型。 我們將獲得除當前用戶外的所有用戶
const users = User.find({ _id: { $ne: user._id } })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.