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
Last updated
Was this helpful?