🔬
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
  • insertOne(<object>)

Was this helpful?

  1. Documentation
  2. Collection

insertOne()

Inserts a single item into Database. If item passed in do not contain the **_id** field, one will be added to each of the items missing it

Example

db.collection("users").insertOne({
    name: "username",
    banned: false,
    accountCreated: new Date().toLocaleDateString()
}).then(() => {
    //Item inserted in db;
    /*
        example output => {
            "_id": "31m16r2xrw85rp3gjq8fe7z6cdl10yuq",
            "name": "username",
            "banned": false,
            "accountCreated": "13/02/2023"
	}
    */
}).catch(error => {
    console.log("error:", error);
});

insertOne(<object>)

Parameter
Description

The item to insert

PreviousupdateOne()NextinsertMany()

Last updated 2 years ago

Was this helpful?

Object