Meteor $in problem with array


#1

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


#2

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
            }
        });

#3

Yes, I m passing:

var recipients = message.recipients;

before I did the findOne (Message)


#4

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?


#5

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.


#6

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?


#7

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


#8

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


#9

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