Some Java Guy Some Java Guy - 1 year ago 92
JSON Question

mongo find function mismatch

Mongo version :


My sample json is as below

enter image description here

My query to fetch
equal to
doesn't work.

db.collection.find( { "": "apple" } )

Instead it fetches all the records, strange?

Neither does the $eq, $lt or $gt work. They result with the entire data.

db.aggregation.find( { "products.foods.min_price": {$eq:10} } )

Thanks in advance.

Answer Source

The solution is to n $unwind both the arrays.

    { $unwind : "$products" },
    { $unwind : "$products.foods" },
    { $match  : { "products.foods.min_price": 10        }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download