MongoDB how select like : SELECT _id, size.h from inventory WHERE status = “A”

https://stackoverflow.com/questions/63389598/mongodb-how-select-like-select-id-size-h-from-inventory-where-status-a

i need the value only it

size.h

SQL like :

SELECT size.h from inventory WHERE status = “A”

and the MongoDB shell how can i do it ?

Hello, @AtlantisDe!

You can use this query:

db.inventory.find(
  { status: 'A' }, // where
  { _id: true, 'size.h': true } // select
);

It will produce the following output:

[
  { "_id" : ObjectId("5f355cdb920ca5b143d09356"), "size" : { "h" : 14 } },
  { "_id" : ObjectId("5f355cdb920ca5b143d09357"), "size" : { "h" : 8.5 } },
  { "_id" : ObjectId("5f355cdb920ca5b143d0935a"), "size" : { "h" : 10 } }
]

Checkout some pages in the official MongoDB documentation:

I strongly recommend you to take some free Basic MongoDB course to be able to resolve such tasks easily :wink:

2 Likes

@slava Thank u very much …i got it…
tks… :grinning: :grinning: :grinning: :grinning: :handshake: :handshake: :handshake: :handshake: :handshake:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.