[CSHARP-1634] aggregation framework should have an $in expression Created: 21/Apr/16  Updated: 27/May/22  Resolved: 23/Aug/16

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Craig Wilson
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-6146 aggregation framework should have an ... Closed
is depended on by DRIVERS-297 Aggregation Framework Support for 3.4 Closed
Epic Link: MongoDB 3.4
Server Compat: 3.3

 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.



 Comments   
Comment by Craig Wilson [ 23/Aug/16 ]

We are already supporting the .NET Contains extension method using $anyElementTrue and $map. While this is likely more efficient, we don't have access to the currently running server version at the time of translation and making this change would break backwards compatibility.

Generated at Wed Feb 07 21:40:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.