Javascript商店作为一个variables逗号分隔的string为mongoDB
我在MongoDB中使用nodeJS。 我试图查询数据库并添加populate
像文档说:
Story .findOne({ title: /timex/i }) .populate('_creator', 'name')
事情是,我需要使用'_creator', 'name'
几次。 我怎样才能在我的文件开始存储这个,以便我可以多次使用它?
使用EMCAScript6,您可以使用扩展运算符将数组用作参数列表...
在文件的开头,你可以创build一个数组:
const params = ['_creator', 'name']
然后在整个代码中引用它:
Story .findOne({ title: /timex/i }) .populate(...params)