2017-03-27 120 views
-1

幫幫我, 我需要編寫shell腳本的蒙戈如何爲mongo編寫shell腳本?

代碼:: mongo data --eval "db.collection1.aggregate({$lookup:{from: "collection2", localField: "id", foreignField: "id", as: "arrCol" }})"

但返回錯誤 語法錯誤:無效的屬性ID @(殼EVAL):1:36

回答

1

腳本片段不應該包含雙引號。你應該在你的查詢中使用單引號表示字符串:

mongo data --eval "db.collection1.aggregate({$lookup:{from: 'collection2', localField: 'id', foreignField: 'id', as: 'arrCol' }})"

否則"db.collection1.aggregate({$lookup:{from: "將interprented因爲你正在傳遞JavaScript片段。