How to find a field that is in quotes?

Hi,

I have created a Document with nested Object like this:
db.inventory.insert(“size”: {“h”: 10, “w”: 15.25, “uom”: “cm”});

and Now I want to find within the Collection “inventory” - such document whose ‘size’ with ‘h’ greater than 5.
My problem is - I tried with this command -

db.inventory.find({“size:h”:{$gt:5}});
It doesn’t show the required document within “inventory”.
I guess the issue is with the name of the field->size, since it is already in double quotes.

Can anyone help me how to get this fetched?

HI Abhishek,

The h is the child of the size.
try with this:
db.inventory.find({‘size.h’:{$gt:5}})

1 Like

Hi Abhishek_81601,

Your approach is absolutely right!

Just one syntax issue: You have to use Dot instead of colon operator.

db.inventory.find({"size.h":{$gt:5}});

Kanika

1 Like

Yeah I figured it out, Thanks Kanika.
Thank you Ramanes as well for your response.