2015-11-23 34 views
1

我有這樣的代碼MongoDB的更新命令行的多條記錄

var new_styles = ["XEP02" ,"XEP65" ,"XEPB01" ,"XEPB03" ,"XN06" ,"XN14" ,"XN73"]; 

for(var i = 0; i < new_styles.length; i++) { 
    var style_name = [i]; 
    var full_length = "/assets/full_length/low_res/" + style_name + ".jpg"; 
    var cropped = "/assets/cropped/low_res/" + style_name + ".jpg"; 
    db.styles.update({"_id": style_name}, {"$push" : {"images.full_lenght": full_length, "images.cropped": cropped }}); 
} 

當我蒙戈控制檯上運行它,它似乎並沒有工作,那裏的

db.styles.update({"_id": "XEP02"}, {"$push" : {"images.full_lenght": "/assets/full_length/low_res/XEP02.jpg", "images.cropped": "/assets/cropped/low_res/XEP02.jpg"}}); 

工作

我在想什麼?

+2

'style_name = [i]'你想用那個做什麼? –

回答

1

有一個錯誤在你的for循環,它目前將查詢"_id":0"_id":1等。您需要將var style_name = [i]更改爲:

var style_name = new_styles[i]; 
+0

傻我,你是對的,謝謝 – khinester