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

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

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Works as Designed
    • Icon: Minor - P4 Minor - P4
    • None
    • 3.4.3
    • Querying
    • 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

            mark.agarunov Mark Agarunov
            hmducoulombier@marketing1by1.com Henri-Maxime Ducoulombier
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: