簡體   English   中英

MongoDB Mongoose按布爾值從查詢中排除結果

[英]MongoDB Mongoose Exclude Results from Query by Boolean Value

編輯

我現在意識到我的查詢有兩個問題。

1(我的原始問題):

在Node / Express中,我試圖按布爾值過濾來自Mongo查詢的結果。 應該足夠簡單吧? 基本上,如果配置文件不完整,我想忽略用戶。

這是查詢中沒有發揮作用的特定部分:

{profileComplete: {$ne: false}}

我嘗試將$ne換成$ne $nin ,但這也不起作用。

我在查詢中出了點問題嗎?

如果有用的話,這是整個查詢:

req.session.query = {$and:
  [
    {learningLanguages: {$in: req.user.spokenLanguages}}, // matches other users' learning languages with the current users spoken language(s)
    {_id: {$nin: [req.user.blockedUsers.split(","), req.user._id]}}, // disregard users who have been blocked by the current user AND the current user him/herself 
    {profileComplete: {$ne: false}} // disregard users who haven't completed their profiles yet.
  ]
}

2:

我還剛剛發現,阻止自己的登錄用戶訪問結果也不起作用。 這是查詢的最后一行: {_id: {$nin: [req.user.blockedUsers.split(","), req.user._id]}}

就在我剛開始接觸MongoDB時。

好,我知道了。 它一直都在工作,但是我在其他地方(不是很遠!)有一個if語句正在創建一個不同的查詢。 h!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM