I would like to get all documents with a string for the field 'readings'. So in this example:
{
"_id": 1,
"readings": "string"
},
{
"_id": 2,
"readings": [
"string"
]
}
... I need to get document 1 as a result, NOT document 2.
I tried this
db.collection.find( { "readings" : { $type: "string" } } )
but this will give me document 2
答案 0 :(得分:1)
Try this now:
db.collection.find( { "readings" : { $type : "string" }, "readings.0": { "$exists": false } } );
Reference: MongoDB Match an array with $type?