How to write nested query?

I understood the following query
db.solarSystem.aggregate([{$match: {type: {$ne: “Star”}}}])
it is matching where the type is not Star and returning all documents
But this time I want to match where value of gravity is greater than 8, I tried to get this but could not.
db.solarSystem.aggregate([{$match: {gravity.value: {$gt: 8}} }]).pretty()
and like this
db.solarSystem.aggregate([{$match: {gravity: {value: {$gt: 8}}}}]).pretty()
but failed… Please help because I want to get depending upon imdb.rating to solve assignment.
Waiting to read your kind response

Hi,
When you try to access the field gravity.value you should have quotes with it: db.solarSystem.aggregate([{$match: {“gravity.value”: {$gt: 8}} }]).pretty() will work.

You need quotes when accessing subfields.

1 Like