Is there any way to get the list of keys of a particular document in MongoDB other than iterate through the document?
i.e I want to get the keys for the document returned by
db.users.find({username:'[email protected]})
Are there any inline commands.If not,can anybody give an idea on how to do?
All documents in a MongoDB collection have a primary key dubbed _id . This field is automatically assigned to a document upon insert, so there's rarely a need to provide it.
Key value databases, also known as key value stores, are database types where data is stored in a “key-value” format and optimized for reading and writing that data. The data is fetched by a unique key or a number of unique keys to retrieve the associated value with each key.
Find() Method. In MongoDB, find() method is used to select documents in a collection and return a cursor to the selected documents.
Object.keys(db.users.findOne({username:'[email protected]'}))
will return a list of all the keys of a particular document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With