我想知道如何將對象數組插入到具有自己的預定義_id值的Mongo集合「根級文檔」中。將對象數組插入到MongoDB中
我試過db.MyCollection.insert(array);
,但它在MongoDB中的一個生成的_id下創建嵌套文檔。
var array = [
{ _id: 'rg8nsoqsxhpNYho2N',
goals: 0,
assists: 1,
total: 1 },
{ _id: 'yKMx6sHQboL5m8Lqx',
goals: 0,
assists: 1,
total: 1 }];
db.MyCollection.insert(數組);
我想
'db.MyCollection.insert(陣列)'應該工作。你是否收到任何錯誤訊息? – styvane
插入過程有效,我正在收集數據,但我希望在「根級別」具有對象,現在它們被插入到「0」下:{},「1」:{}等等。我想用我的_id值將所有對象作爲「根級」文檔插入 – justdiehard
使用您向我們顯示的文檔,您無法獲得該結果。 – styvane