Mongo find and $in code review

Hi All,

Hoping for some extra pairs of eyes as to why the results from my find is coming back with an empty array.

Here is my code:

  = Camps.findOne(this.campId);

            if ( {
                console.log(" ",;
                /// console.log >>>  ["aXPMKtJeCZstLh3yZ", "NXpwF2cwucRMKn4hN"]
                this.campers = Campers.find({_id: { $in: }}).fetch();
                console.log("this.campers", this.campers);
                /// console.log >>> this.campers []

In the mongo shell I run this command:

db.campers.find({_id:{$in:["aXPMKtJeCZstLh3yZ", "NXpwF2cwucRMKn4hN"]}})

This returns me the two documents I was expecting. Any ideas as to what I’m doing wrong?

That doesn’t look right. How about this?


Thanks for the response @SkyRooms.

I tried specifying the field value and still get the same result.

The findOne does return a valid camp, however the $in query returns and empty array.

This may be a rather basic question but let’s make sure: Are you actually publishing the documents you expect to be found?

So you tried _id:“aXPMKtJeCZstLh3yZ” and got two results?

He’s searching in two different collections. Collection Camps is the one he did the findOne() on. And then there’s collection Campers which he’s trying to find multiple results in.

Hence my question whether he actually publishes the Campers collection’s documents to the client. Because the query does look correct (and it does work in the mongo shell).