push()

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

Syntax

db.push(path,element,listener?)
  • 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",(err,data) => {
    if(err) return console.log(err.message)
    console.log("Added smart phone")
    console.log(data)
})
/*
{
    name:"John",
    surname:"Doe",
    age:18,
    bag:["smart phone"]
}
*/

Last updated