How to find all Book with Author condition in collection-helpers package?


#1

I would like to find all Book that Author condition of gender = “Male”.

books: function () {
        return Books.find({
            "author.gender": 'M'
        });
    }

pl help me.


#2

The good solution:

books: function() {
  var authorIds = Authors.find({ gender: 'M' }).map(function(author) { return author._id; });
  return Books.find({ authorId: { $in: authorIds }});
}

#3

In my opinion, your first code should work, no need for the second one.

I don’t think your question relates to the collection-helper package, does it? You might want to change the title of your question.


#4

I don’t to use embed document.
I have two collection Books and Authors, and then want to get all books with gender = “M” of author condition.
I think that the second code it is slow and difficult to manage the many relation of collection