🔬
Moonlight.DB
GitHubNPM
  • Introduction
  • Getting Started
  • Documentation
    • Database
      • createCollection()
      • deleteCollection()
      • collections
    • Collection
      • find()
      • findOne()
      • update()
      • updateOne()
      • insertOne()
      • insertMany()
      • delete()
      • deleteOne()
      • length
Powered by GitBook
On this page
  • Example
  • insertMany(Array<Object>)

Was this helpful?

  1. Documentation
  2. Collection

insertMany()

Inserts an array of items into database. If items passed in do not contain the **_id** field, one will be added to each of the items missing it

Example

db.collection("users").insertMany([
	{a: "123"},
	{b: "456"},
	{c: "789"}
]).then(() => {
    //Items inserted in db;
    /*
    	example output => [
    		{
    			"_id": "m0i1s85b9cui2qr4ys8bqvl8wczr51em",
			"a": "123"
		},
		{
			"_id": "1n608o008q24ul39ssyqniq5b9i33cx7",
			"b": "456"
		},
		{
			"_id": "3cfp5p75x5vi1hk9cly140zgy1fs50g7",
			"c": "789"
		}
	]
    */
}).catch(error => {
    console.log("error:", error);
});

insertMany(Array<Object>)

Parameter
Description

The items to insert

PreviousinsertOne()Nextdelete()

Last updated 2 years ago

Was this helpful?

<>

Array
Object