0

My schema of users is like this:

{
name: String,
posts:[
    {
    title: String,
    comments:[
      {
        country: String,
        tags:[
         {
            title: String
         }]
      }]
    }]
}

I want to push a tag into a specific comment of specific post.

I tried with this:

db.getCollection('users').update(
{"name" : "javier", "posts.title": "sometitle", "posts.comments.country": "ES"},
{$push:{"posts.$.comments.$.tags":{"title":"sometag"}}});

But mongoDB doesnt accept using two $. So how can I push the tag?, is it possible in mongoDB? Do I have bad concept of schemas? Thanks in advance.

Javier
  • 33
  • 1
  • 3
  • That's really nested. you might consider putting comments in it's own collection. – chapinkapa Dec 11 '15 at 22:01
  • I think this can be helpful: [http://stackoverflow.com/questions/19603542/mongodb-update-data-in-nested-field](http://stackoverflow.com/questions/19603542/mongodb-update-data-in-nested-field) – Marcin T.P. Łuczyński Dec 11 '15 at 23:34

0 Answers0