mongoose query for an array of dictionaries

How do you work with arrays that contain dictionaries? I'm trying to get together all the post fields so I can search their text.

My attempts keep going nowhere using mongo shell.

User.Blog().find({}).where('post').in(writing).exec(function (err, result) {
  //do something with results
}); // doesn't work

schema (edit: fixed from @JAM comments)

var blogSchema = new mongoose.Schema({
  group:  String,
  writing: [{
        post: String,
        name : Number
        }]
});

var Blog = mongoose.model('Blog', blogSchema);

Update: adding json data and the command to put data in mongodb using mongo shell:

{
  group:  "Design Writing",
  writing: [{
        post: "A very very very short post.",
        name:  10
  }, {
        post: "An early morning post about everything.",
        name:  11
  }]
}

*Or, here as one line to insert into a db in the collection named my_collection: *

db.my_collection.insert( {group:  "Design Writing", writing: [{post: "A very very very short post.",name:  10}, {post: "An early morning post about everything.",name:  11}]} )

Objects in your writing array is treated as sub/embedded-documents. This means that they are assigned an _id when they are stored in the database.

So, there is a few ways you can query Blogs based on these sub documents:

var ObjectId = mongoose.Types.ObjectId;

// Assuming these objects are in the 'writing' array of a Blog
var postObject = { post: 'some text', name: 10 },
    postObjectWithId = { _id: new ObjectId(), post: 'some text', name: 10 };

// Example #1 Works!
Blog.find({'writing.post': postObject.post})
    .exec(function(err, res){ onBlogResult("Ex#1", err, res) });

// Example #2 Works!
Blog.find({})                        
    .where('writing').in([postObjectWithId])
    .exec(function(err, res){ onBlogResult("Ex#2", err, res) });

// Example #3 Works - its the same as example #2!
Blog.find({'writing': { $in: [ postObjectWithId ]}})
    .exec(function(err, res){ onBlogResult("Ex#3", err, res) });

// Example #4 Fails because of missing _id on postObject!
Blog.find({'writing': { $in: [ postObject ]}})
    .exec(function(err, res){ onBlogResult("Ex#4", err, res) });

As you see, you can only find objects with an array containing an element using in if you have the full object (including the _id).

You can view the whole source on this GIST - Test it out for yourself :)

Hope this helps :)

Read the mongoose docs here.