Possible duplicate:
Why you cannot change the data returned by Mongoose Query (for example: findById)
First I make a request in mongoDB, I get all the correct results, but only a small modification of the object literal does not work. What I'm trying to do is add a new field to the comments. I tried using the DBref method, but it did not work, so I make 2 queries.
var query = Rss.findOne({ _id: itemId});
query.exec(function(err, feed) {
if (!err && feed.comments) {
console.log(feed.comments.length);
for (var index in feed.comments) {
var author = feed.comments[index].author;
if (author !== undefined) {
User.findById(author, function(err, user) {
feed.comments[index].name = 'Some random field';
console.log('Added new field' + util.inspect(feed));
});
}
}
}
});
Also, the answer will be absent without the .name field.
Added new field{ _id: 4f34f343c7b0434217000012,
original_link: 'http://com',
publish_date: Fri, 10 Feb 2012 10:36:00 GMT,
summary: 'some text',
title: 'title exampel',
comments:
[ { body: 'well',
author: 4f30265e6f60dc061d000002,
_id: 4f34f3b6f96c58541700000f,
create_date: Fri, 10 Feb 2012 10:38:46 GMT } ],
create_date: Fri, 10 Feb 2012 10:36:51 GMT }
// EDIT additional information
Well, I did not find the answer, but some, like console.log (feed.comments [index]) returns a link to the function. Maybe someone with more experience with Mongoose can explain what will be the workaround in this situation.
{ [Function] author: 'Some random field' }