mongodb - mongo find function mismatch -


mongo version : 3.2.8

my sample json below

enter image description here

my query fetch name equal apple doesn't work.

db.collection.find( { "products.foods.name": "apple" } ) 

instead fetches records, strange?

neither $eq, $lt or $gt work. result entire data.

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

thanks in advance.

if entire document in _id, if query matches db.collection.find( { "products.foods.name": "apple" } ) though document in foods array entire document displayed, getting other fruits well.

to solve first use $unwind aggregation pipeline break foods array individual documents , use $match.

please refer post, similar question , have answered steps in detail in post.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -