push()

You can add an element to an array using with push()

Syntax

db.push(path,element,callback?)
  • Path; Path is a string, split with dot and required.

  • Element; All types are acceptable and required.

  • Callback; Callback is a function and not required.

Example

db.push("user.john.bag","smart phone",(callback) => {
console.log("Added smart phone")
console.log(callback)
/*
{
    name:"John",
    surname:"Doe",
    age:18,
    bag:["smart phone"]
}
*/
})

Last updated