Home:ALL Converter>Documentation? and is $nin in mongodb Aggregation or not?

Documentation? and is $nin in mongodb Aggregation or not?

Ask Time:2018-01-12T11:29:29         Author:Michael Dimmitt

Json Formatter

For the 4.6 mongo aggregation docs on operator expressions, $in is mentioned and $not is mentioned but $nin is not mentioned. https://docs.mongodb.com/v3.6/meta/aggregation-quick-reference/#agg-quick-ref-operator-expressions

$nin is explained for find and update in the docs. https://docs.mongodb.com/manual/reference/operator/query/nin/

On jira for those logged in with access solutions are given using $nin with aggregation examples. https://jira.mongodb.org/browse/SERVER-9030?focusedCommentId=294125&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-294125

But is $nin a valid operation, because it is not in the docs. Or as an alternative will $in and $not, combined return documents with $nin functionality?

example:

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

alternative example,

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

wow, when I was writing the example I think I figured it out. If I want $nin I should just match where $in returns false.

Hopefully, there is still reason to post the question as it provided me with confusion and may have confused others. regards, Michael Dimmitt

Author:Michael Dimmitt,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48219158/documentation-and-is-nin-in-mongodb-aggregation-or-not
yy