$in operator complains about var not being an array, if it is

XMLWordPrintableJSON

    • Type: Question
    • Resolution: Works as Designed
    • Priority: Minor - P4
    • None
    • Affects Version/s: 3.4.3
    • Component/s: Querying
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      When running a query like that, we have an error "$in operator needs an array", even if the content of $oi expression is an array.

      
      db.demo.aggregate(
      [
      	{"$match":{"_id":{"$in":["aaa","bbb"]}}},
      	{"$project":{
      		"order_items":1,
      		"orders":1,
      		"oi":'$order_items.order_id'
      	}},
      	{
      	 "$addFields":{"sz":{"$size":"$oi"}} // This works, $oi is an array and $size works on arrays
      	},
      	{"$match":{"orders.order_id": {"$in":"$oi"}} // This does not work even if $oi is an array
      ]
      )
      

      I guess this is complicated for query engine to be sure that $oi is an array, and $in operator has been strengthen considering the fact that value must be an array, but is there a way to achieve that ?

            Assignee:
            Mark Agarunov (Inactive)
            Reporter:
            Henri-Maxime Ducoulombier
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: