docs icon indicating copy to clipboard operation
docs copied to clipboard

Mention that $type can't inspect array elements

Open dandv opened this issue 6 years ago • 1 comments

dandv avatar Jun 13 '19 03:06 dandv

Hey @dandv -- didn't forget about this pull. It's because I want to kind of finesse the wording since we can use $arrayElemAt to pass in an array element to the $type. So, definitely get the gist of your pull, just thinking things through.

MongoDB Enterprise > db.foo.find()
{ "_id" : ObjectId("5d72d8df9eecd5d9513aa02f"), "x" : [ "1", "2" ] }
MongoDB Enterprise >  db.foo.aggregate( [  { $project: { myType: { $type: {$arrayElemAt: [ "$x", 0 ] } } } } ] )
{ "_id" : ObjectId("5d72d8df9eecd5d9513aa02f"), "myType" : "string" }

kay-kim avatar Sep 06 '19 22:09 kay-kim