0

I want to send parameters to populate function of Mongoose JS.

.populate('friends', { username: 1, age: 1})

How should I pass these variables in an object? So I will call this function like:

.populate(populationVars)
2
  • What does populationVars look like? Commented Jan 18, 2017 at 13:47
  • That is exactly what I wonder to know:) Commented Jan 18, 2017 at 13:48

1 Answer 1

2

You could use apply I suppose:

var populationVars = ["friends", { username: 1, age: 1}];
fn.populate.apply(null, populationVars);
Sign up to request clarification or add additional context in comments.

2 Comments

I'm getting TypeError: Cannot read property 'populate' of undefined in node_modules/mongoose/lib/query.js:2719:27 if (!utils.isObject(opts.populate)) { opts.populate = {}; }
@Burak - That means opts is undefined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.