How can I search an embedded collection within MongoDB?

By : Hoa

For example suppose I have a Post schema as follows:

var Schema = new db.Schema({
    title    : String
    , text    : String

    // Denormalize by using user name
    , author     : String
    , tags: [String]
    , comments: [Comment]

I'm trying to match a particular tag as follows:

function getPostByTag(tag, callback) {
    Post.find().where({"tags.value": tag}).run(callback);

But it is returning everything. What am I doing wrong?

By : Hoa


Where are you getting the "value" part of "tags.value". Shouldn't it just be:


This video can help you solving your question :)
By: admin