Query condition in populate

1,598 views
Skip to first unread message

Sergey

unread,
Oct 23, 2011, 11:04:54 PM10/23/11
to mongoo...@googlegroups.com
Hi!
I am using version 2.3.6
I am trying to use the query conditions in populate method, but I am facing the issue described in https://github.com/LearnBoost/mongoose/pull/553
namely, if a condition is used then still all the records are populated but ones that don't satisfy the condition have the populated field is set to null, i.e. if I use the same schemas as in https://groups.google.com/forum/#!topic/mongoose-orm/A8qAGxihF3o and perform a query like:
var query = BookModel.find();
query.populate('author','name',{name:'author1'});
query.find(function(err,books){
  console.log(books);
    process.exit(0);
});
Then the output is:
[  { author: { _id: 4ea0db52e09aa6aad2e831fe, name: 'author1' },
    title: 'book1',
    _id: 4ea0dbebc191848704000005 },
  { author: null,
    title: 'book2',
    _id: 4ea0dbebc191848704000006 } ,
  { author: null,
    title: 'book3',
    _id: 4ea0dbebc191848704000007 } ,
  { author: null,
    title: 'book4',
    _id: 4ea0dbebc191848704000008 } ]

However, I expect only the 1st record in the output result. As you mentioned in https://github.com/LearnBoost/mongoose/pull/553
It seems that you have fixed that, but the fix is not in the 2.3.6 release..could you tell me how I can get the fix? 

Aaron Heckmann

unread,
Oct 24, 2011, 11:37:27 AM10/24/11
to mongoo...@googlegroups.com
This is different than what was discuessed in pull 553 which was about a document with a child array of ObjectIds and populating them. You have an array of documents and are populating one subproperty on each. If the document is not found, null is returned.

--
http://mongoosejs.com
http://github.com/learnboost/mongoose
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en



--
Aaron


Sergey

unread,
Oct 26, 2011, 1:08:00 AM10/26/11
to mongoo...@googlegroups.com
So, are you saying that the behavior I observe is correct?

Aaron Heckmann

unread,
Nov 4, 2011, 11:29:34 AM11/4/11
to mongoo...@googlegroups.com
yes

On Wed, Oct 26, 2011 at 1:08 AM, Sergey <s.aba...@gmail.com> wrote:
So, are you saying that the behavior I observe is correct?

--
http://mongoosejs.com
http://github.com/learnboost/mongoose
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en



--
Aaron


Reply all
Reply to author
Forward
0 new messages