Chp 4, Array Operators, Question 1 -- array size - error

I’m having trouble with these two statements in the shell, in find( ).

{“accommodates”: {"$gt": 6}},{“reviews”: {"$size": 50}}

The two statements above work as expected in the graphical viewer but in the shell as

db.listingsAndReviews.find(
{“accommodates”: {"$gt": 6}},{“reviews”: {"$size": 50}}
)

… they produce this error:

MongoDB Enterprise atlas-14e5fx-shard-0:PRIMARY> db.listingsAndReviews.find(
… {“accommodates”: {"$gt": 6}},{“reviews”: {"$size": 50}}
… )
Error: error: {
“operationTime” : Timestamp(1631571411, 1),
“ok” : 0,
“errmsg” : “The argument to $size must be an array, but was of type: double”,
“code” : 17124,
“codeName” : “Location17124”,
“$clusterTime” : {
“clusterTime” : Timestamp(1631571411, 1),
“signature” : {
“hash” : BinData(0,“hbOk7buM0J/ni8jaWFKWxuJdJ54=”),
“keyId” : NumberLong(“6968918440186740737”)
}
}
}
MongoDB Enterprise atlas-14e5fx-shard-0:PRIMARY>

I’d like to get past the error in the shell, but I’m also curious why they work in the Data viewer.

I had my { } wrongly placed. It should have been:

db.listingsAndReviews.find(
{“reviews”: {"$size": 50},
“accommodates”: {"$gt": 6}}
)

This worked.

1 Like