Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31055

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

    XMLWordPrintable

    Details

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

      Description

      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 ?

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: