JavaEvgen JavaEvgen - 3 months ago 19
Node.js Question

How to get an _id of parent document mongoose

I'm trying to implement a method in express router, that would delete an embedded document from a parent document by its


My code looks like this:


<table class="table table-striped table-bordered">
<table class="table table-striped table-bordered">
{{# each movie.comments}}
<td><a href="comment/delete/{{movie._id}}/{{this._id}}">Delete</a></td>

I can easily get an _id of my embedded doc (single comment), but I can't get an _id of my parent (movie) doc.

On back-end everything seems to be ok, but I get 404 error, because movie._id is empty so my
doesn't match its pattern in router.

I populate my view with this:

Movie.findById('comments').exec(function(err, movie)

and render the movie object


Since the context changes in #each, try going up a level:

<a href="comment/delete/{{../movie._id}}/{{this._id}}">Delete</a>