1

I'm using nodeJS with MongoDB. I'm trying to query the DB and add populate like the doc says:

Story
.findOne({ title: /timex/i })
.populate('_creator', 'name')

The thing is, I need to use '_creator', 'name' several times. How can I store this at the start of my file so that I can use it multiple times?

1 Answer 1

2

With EMCAScript6, you can use an array as a parameter list using the spread operator ...

At the beginning of the file, you can make an array:

const params = ['_creator', 'name']

And then reference it throughout your code as:

Story
.findOne({ title: /timex/i })
.populate(...params)
Sign up to request clarification or add additional context in comments.

Comments

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.