Object.keys, How To Get A List Of Keys In Mongodb
{ '_id': '1', 'style': '13123', 'category': 'dress', 'colors': { 'Black': { 'prestock': 50, 'instock': 60, 'inactive': 0 }, 'Blue': {
Solution 1:
A query like {"colors.*.prestock" : {$gte:30}}
isn't possible according to SERVER-267, and I doubt this will be supported in the next years.
Your best bet is to change the schema to an array:
colors: [
{ "color" : "Green", "instock" : 50, ... },
{ "color" : "Yellow", "instock" : 50, ... },
]
Then you can query
db.foo.find( {"colors.prestock" : {$gte:30}} )
Note that this will return the entire object, including all colors, i.e. also those for which the query constraint doesn't hold. This could be solved using the aggregation framework, but again, only using $unwind
which also requires colors
to be an array.
Solution 2:
Is this is what you are looking for? MongoDB Get names of all keys in collection
If not, then the Application must have a list of keys or enum values that has all the possible combinations, you will have to Query and go through them.
Post a Comment for "Object.keys, How To Get A List Of Keys In Mongodb"