【MongoDB學習筆記6】深入MongoDB的建立/插入(insert)

來源:互聯網
上載者:User

標籤:insert   mongodb   

簡單單個文檔插入用insert方法:  

> db.post.insert({"bar":"baz"});    WriteResult({ "nInserted" : 1 })

 批量插入,用insert方法(參數要是一個文檔數組):

> db.post.insert([{"_id":0},{"_id":1},{"_id":2}]);   BulkWriteResult({            "writeErrors" : [ ],            "writeConcernErrors" : [ ],            "nInserted" : 3,            "nUpserted" : 0,            "nMatched" : 0,            "nModified" : 0,            "nRemoved" : 0,            "upserted" : [ ]    })    >

查看插入的結果:  

> db.post.find();    { "_id" : ObjectId("54a51cfd7f46906f81b7adcd"), "bar" : "baz" }    { "_id" : 0 }    { "_id" : 1 }    { "_id" : 2 }    >


附註:batchInsert方法在新版的mongoDB中已經不可用;


本文出自 “緣隨心愿” 部落格,請務必保留此出處http://281816327.blog.51cto.com/907015/1598300

【MongoDB學習筆記6】深入MongoDB的建立/插入(insert)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.