0

I am pretty new to mongodb, and I am not able to query in my mongo collection.

Structure :

"chapterId":1,
"videos" : [ 
        {
            "videoId" : "1",
            "videoName" : "about",
            "duration" : "12:36",
            "tags":["business", "design"]
        }, 
        {
            "videoId" : "2",
            "videoName" : "course",
            "duration" : "04:00",
            "tags":["technology", "design"]
        }
]

I need to select all videos with the tag "business" in chapterId 1.

Can this be done without changing the structure of my collection ?

1 Answer 1

3

You should use aggregation so below query will help you

db.collectionName.aggregate(
          {"$unwind":"$videos"},
          {"$match":{"chapterId":1,"videos.tags":"business"}}
          )
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.