Meteor $in problem with array

Hey forum,

I want to do this query on SERVER:

return Meteor.users.find({ _id: { $in: recipients } }, {
            fields: {
                username: 1
            }
        });

But i have this array witch store this ids:

I pass the array parameter (recipients) to the method, but i think i cant do that because it is not well formated.

What I need to do before pass the Recipients array?

Thx

Where is the object that you posted coming from? You will need to pass in something like myObject.recipients, so it would look like:

let recipients = myObject.recipients;

return Meteor.users.find({ _id: { $in: recipients } }, {
            fields: {
                username: 1
            }
        });

Yes, I m passing:

var recipients = message.recipients;

before I did the findOne (Message)

Well, your query looks well-formed to me, then. Are you sure it’s not a data problem? Can you pass a hard-coded array that you know should work?

2 Likes

in order to use $in this is the format you need to use

return Meteor.users.find( { _id : { $in: [ 5, 15 ] } } )

so your recipients needs to be an array.

I don’t understand what the actual issue is. Is there an error of some sort? Why can’t you just pass the recipients array into a method and run the query?

What the hell is going on? That’s not funny… :cold_sweat:

1 Like

Perhaps Use findOne, and or create an array object and place each value in it.

Viewmodel wraps arrays into reactive arrays.
fileIds.array() works fine. But it’s my case.