jeroen/mongolite

Error when try to sort in find or aggregation by type of field with "{$type: "array"} operator

Opened this issue · 0 comments

Got error:

tmp_mongo$find('{"name": {"$type": "array"}}')
"Missing` "$binary" after "$type" reading type "binary""

when tried to select documents by type of field from collection with find or aggregation (tmp_mongo$aggregate('[{"$match": {"name": {"$type": "Array"}}}]) queries. The error stays same with any BSON type from MongoDB manual , replacing alias to integer form give another error:

tmp_mongo$find('{"name": {"$type": 4}}')
Error: Unexpected integer 4 in type "binary"

Couldn't find anything about using $type in mongolite, suppose some error with recognizing of this operator syntax. Same queries in mongosh works fine:

db.tmp.findOne({"name": {"$type": 4}})
db.tmp.findOne({"name": {"$type": "array"}})
db.tmp.aggregate([{$match: {"name": {"$type": 4}}}, {$limit: 1}])

{
_id: '572257509',
name: []
}

MongoDB 5.0.8 Community, mongolite version 2.7.1