mongodb $elemMatch with multiple values

Fabrizio Bertoglio

I want to query the following Movie object based on his tags array with Mongodb

Movie.last.tags
 => [{"type"=>"Genre", "tags"=>["Comedy"]}, {"type"=>"score", "tags" => ["Excellent"]}] 

by using $elemMatch

Movie.where({'tags' => {'$elemMatch' => {'type' => "Genre", "tags" => "Comedy"}}})

I can query all entries with the Comedy tag, but I need to restrict the search to those that have in their tags array also {"type"=>"score", "tags" => ["Excellent"]}

Fabrizio Bertoglio

You found the solution @Veeram, please copy this answer and edit to your wish. I will accept it and I'll be thankful to you for sharing your expertise with us

Movie.where({'tags' => { '$all' => [
                        {'$elemMatch' => {'type' => "Genre", "tags" => "Comedy"}},
                        {'$elemMatch' => {'type' => "score", "tags" => "Excellent"}}
                        ]}
            })

Thanks a lot Best Regards Fabrizio

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MongoDB: multiple $elemMatch

From Dev

MongoDB elemmatch multiple elements in array

From Dev

MongoDB $elemMatch $in

From Dev

MongoDB - How can I use $elemMatch with multiple criteria

From Dev

MongoDB $elemMatch in Meteor

From Dev

mongodb find with opposite of $elemMatch

From Dev

Combining $elemMatch and $ in mongodb projection

From Dev

MongoDB: $elemMatch issue

From Dev

MongoDb $elemMatch is not working as expected

From Dev

$in query with $elemMatch in mongoDB

From Dev

MongoDB - Updating multiple levels of subdocuments with multiple $elemMatch operators in node.js

From Dev

mongodb aggregation of multiple values

From Dev

MongoDB - Use $where inside $elemMatch

From Dev

MongoDB: $nin and $in not working together in $elemMatch

From Dev

Mongodb $elemMatch query inside map

From Dev

MongoDB elemMatch does not work expected

From Dev

MongoDB $elemMatch with 2 properties condition

From Dev

MongoDB simplifying double $elemMatch query

From Dev

MongoDB elemMatch does not work expected

From Dev

MongoDB and PyMongo: Upsert multiple values

From Java

mongodb group values by multiple fields

From Dev

mongoDB `upsert` with multiple key values

From Dev

Not Able To Insert multiple values into mongodb

From Dev

Update in MongoDB multiple values in array

From Dev

Getting Distinct values of multiple values in Mongodb

From Dev

Search multiple fields for multiple values in MongoDB

From Dev

How to group by multiple columns and multiple values in mongodb

From Dev

MongoDB query with elemMatch for nested array data

From Dev

MongoDB indexes not working when executing $elemMatch