【问题标题】:MongoDB Mongoose Exclude Results from Query by Boolean ValueMongoDB Mongoose 按布尔值从查询中排除结果
【发布时间】:2017-03-23 20:04:15
【问题描述】:

编辑

我现在意识到我的查询有两个问题。

1(我原来的问题):

在 Node / Express 中,我试图通过布尔值过滤 Mongo 查询的结果。应该够简单吧?基本上如果配置文件不完整,我想忽略用户。

这是查询中没有打球的特定部分:

{profileComplete: {$ne: false}}

我尝试将$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 的时候。

【问题讨论】:

    标签: node.js mongodb express mongoose database


    【解决方案1】:

    好的,我想通了。它一直在工作,但是我在其他地方(不是很远!)有一个 if 语句,它正在创建一个不同的查询。呵呵!

    【讨论】:

      猜你喜欢
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 2015-01-10
      相关资源
      最近更新 更多