Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-9552

Docs for SERVER-6146: aggregation framework should have an $in expression

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: 01112017-cleanup
    • Component/s: None
    • Labels:

      Description

      Engineering Ticket Description:

      Syntax

      {$in: [<arbitrary expression>, <arbitrary array expression>]}
      

      Examples

      db.coll.insert([
        {_id: 0, x: "Bob"}
      ]);
      > db.coll.aggregate([{
        $project: {
          hasBobOrRob: {$in: ["$x", ["Bob", "Rob"]]}
        }
      }]);
      {_id: 0, hasBobOrRob: true}
       
      // Example 2
      > db.coll.insert([
        {_id: 0, x: "aaa"},
        {_id: 1, x: /^a/}
      ]);
      > db.coll.aggregate([{
        $project: {
          matches: {$in: ["$x", [/^a/]]}
        }
      }])
      {_id: 0, matches: false}
      {_id: 1, matches: true}
      // Note the intentional inconsistency.
      > db.foo.find({x: {$in: [/^a/]}})
      {_id: 0, x: "aaa"}
      {_id: 1, x: /^a/}
      

      Notes

      • Should result in the same values as a $in in a MatchExpression (except with regexes).
      • Should not do regex matching if the values in the array are regexes.
      • This is different from what the query system does, a query predicate of {x: {$in: [/^a/]} will find strings which start with "a". This is arguably a bug in query, and will not be duplicated here.

      Errors

      • If the second expression is not an array.
      • If there are not two arguments passed to the expression.

      Old Description
      Currently expressions like $eq, $ne, $gt, etc are supported but there is no $in available to test set membership.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since reply:
                  3 years, 3 days ago