帮帮我, 我需要为mongo编写shell脚本
代码::
mongo data --eval "db.collection1.aggregate({$lookup:{from: "collection2", localField: "id", foreignField: "id", as: "arrCol" }})"
但返回错误 SyntaxError:无效的属性id @(shell eval):1:36
答案 0 :(得分:1)
脚本片段不应包含双引号。您应该在查询中对字符串使用单引号:
mongo data --eval“db.collection1.aggregate({$ lookup:{from: 'collection2',localField:'id',foreignField:'id',as:'arrCol' }})“
否则var dates= ["Mar 02, 2017", "Mar 02, 2017", "Mar 01, 2017", "Mar 01, 2017", "Mar 01, 2017", "Mar 01, 2017", "Mar 01, 2017", "Mar 01, 2017", "Mar 01, 2017"]
var arrayObjects = dates.map(function(date) {
return {date: date}
})
console.log(arrayObjects)
将被作为您传递的JavaScript片段插入。