Home:ALL Converter>Search for a dynamic field in a mongodb collection

Search for a dynamic field in a mongodb collection

Ask Time:2015-02-05T05:04:25         Author:user3799658

Json Formatter

If I were to search for a particular field in a mongodb collection my command would look something like this :

db.collection.find({ name : "John"})

If I want to make the field name dynamic, what would the command be?

Example:

db.collection.find({ <Dyanmic field variable> : <Value>})  

Or is there an alternative to achieve this function?

Author:user3799658,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28331408/search-for-a-dynamic-field-in-a-mongodb-collection
alecxe :

Just use the variable in place of the dictionary key:\n\nname = 'field_name'\ndb.collection.find({name : \"John\"})\n",
2015-02-04T21:25:24
yy