javascript 如何在mongodb中插入多个文档?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 如何在mongodb中插入多个文档?相关的知识,希望对你有一定的参考价值。

db.collectionName.insertMany( [ <document 1> , <document 2>, ... ])

// example

db.patients.insertMany([{
  "firstName": "Max",
  "lastName": "Martinez",
  "age": 29,
  "history": [{
    "disease": "cold",
    "treatment": "Drink strange thinks"
  }, {
    "disease": "headache",
    "treatment": "Work less"
  }]
}, {
  "firstName": "Pedro",
  "lastName": "Cattaneo",
  "age": 15,
  "history": [{
    "disease": "stomach ache",
    "treatment": "stop eating fast food"
  }]
}, {
  "firstName": "Maria",
  "lastName": "McCartney",
  "age": 45,
  "history": [{
    "disease": "indigestion",
    "treatment": "stop watching tv durin the lunch"
  }]
}])

以上是关于javascript 如何在mongodb中插入多个文档?的主要内容,如果未能解决你的问题,请参考以下文章

javascript 如何在mongodb中插入多个文档?

如何将 HTML 插入 Mongodb?

使用 mongoengine 将多文档插入到 mongodb

mongodb数据库批量插入海量数据时为啥有少部分数据丢失

javascript 使用Mongoose将数据插入MongoDB

MongoDB插入多条数据