These are chat archives for Automattic/mongoose

10th
Jan 2016
Pete Redmond
@httpete-ire
Jan 10 2016 00:39

@vkarpov15 thanks for your help, I think I'll just have to do without the specific error messages. Its only a side project so it not a big deal.

I do have another question though, I'm trying to update a specific embedded document but I think my query is incorrect. Here is my query

  // where statment
  let whereStatement = {
    $and:[
      {
        _id: req.params.docid
      },
      {
        'chapters._id': req.params.chapterid
      },
      {
        'chapters.pullrequest.set': false
      }
    ]
  };

  // find and update a chapters pull request object if set to false
  let updateStatement = {
    'chapters.$.pullrequest': {
      set: true,
      message: req.body.message,
      content: {
        markdown: req.body.markdown,
        html: req.body.html
      }
    }
  };

  let query = Doc.update(whereStatement, updateStatement);

Whats happening though is that the query is updating the first chapter who's pullrequest.set is set to false not the chapter who's ID matches chapters._id. Can you see an issue with my query or am I approaching the query the wrong way. Thanks