Skip to content

API reference

add

Adds a new document to the specified collection.

Parameters

PropTypeDescription
pathstringThe name of the collection to add to
dataRecord<string, unknown>The document data to be added

Returns

  • Returns a promise that resolves to the newly added document: NaroDocument.

Example

js
const db = new Naro("myDatabase");

const newUser = await db.add("users", { name: "John Doe", age: 30 });
console.log(newUser);

// Output: 
{ 
  name: "John Doe", 
  age: 30,
  id: "generated-id", 
  createdAt: 1696872345000,
  path: "users/generated-id",
}

Released under the SSPL License.