【问题标题】:Documentation? and is $nin in mongodb Aggregation or not?文档?并且 $nin 是否在 mongodb 聚合中?
【发布时间】:2018-01-12 11:30:16
【问题描述】:

对于运算符表达式的 4.6 mongo 聚合文档,提到了 $in 并提到了 $not 但没有提到 $nin。 https://docs.mongodb.com/v3.6/meta/aggregation-quick-reference/#agg-quick-ref-operator-expressions

$nin 在文档中解释了查找和更新。 https://docs.mongodb.com/manual/reference/operator/query/nin/

使用 $nin 和聚合示例为那些使用访问解决方案登录的用户在 jira 上给出。 https://jira.mongodb.org/browse/SERVER-9030?focusedCommentId=294125&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-294125

但是 $nin 是一个有效的操作,因为它不在文档中。 或者作为替代方案,$in 和 $not 将返回文件与 $nin 功能相结合?

示例:

db.collection("collection).aggregate([
{
  $match {
    'fieldname': {$nin: ['10', '20','2']}
  }
}
])

另一个例子,

db.collection("collection).aggregate([
{
  $project: {
    "store location" : "$location",
    "has bananas" : { $in: [ "bananas", "$in_stock" ] }
  }
}
{
  $match: { "has bananas": 0 }
}
])

哇,当我写这个例子时,我想我明白了。 如果我想要 $nin,我应该只匹配 $in 返回 false 的位置。

希望仍然有理由发布这个问题,因为它让我感到困惑,并且可能让其他人感到困惑。 问候,迈克尔·迪米特

【问题讨论】:

    标签: mongodb aggregation-framework


    【解决方案1】:
    db.collection("collection).aggregate([
    {
      $project: {
        "store location" : "$location",
        "has bananas" : { $in: [ "bananas", "$in_stock" ] }
      }
    }
    {
      $match: { "has bananas": 0 }
    }
    ])
    

    哇,当我写这个例子时,我想我明白了。

    如果我想要 $nin,我应该只匹配 $in 返回 false 的位置。

    希望仍有理由发布这个问题,因为它让我感到困惑,并可能让其他人感到困惑。

    如果这个解决方案不正确并且可以被证明,我会将正确的解决方案标记为答案。 问候,迈克尔·迪米特 https://docs.mongodb.com/v3.6/reference/operator/aggregation/in/

    【讨论】:

    • 我不明白他们是如何获得那些不在安排范围内的,你能给我解释一下吗?当然,如果不麻烦的话,我也有类似的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 2017-03-18
    • 2016-08-17
    相关资源
    最近更新 更多