DAB
Search…
create
1
create(body, params)
Copied!

Arguments

Body (required)

Document body should be a plain javascript object. If ID is not provided, it'll be created automatically.
If collection has fields definition, than the document body will be sanitized according to its type. Columns that aren't listed in collection fields will also discarded. This is to make sure that you'll always get a clean and correct document saved in the database.

Params (required, mixed)

A plain javascript object of:
  • collection: Required, the name of collection you want to work with.
  • ignoreColumn: If you want some columns to be ignored on validation process (only in enforced attributes), put its attribute id here. Optional, defaults to [].
Or, you're also allowed to pass a string. In this case, it will be interpreted as the collection name.

Response

Result

It should return an object like the one below:
1
{
2
success: true,
3
data: {
4
_id: 'james-bond',
5
name: 'James Bond',
6
age: 40
7
...
8
}
9
}
Copied!

Error

If the ID has been used before, it'll yield Document already exists error.
Any other error will yield a normal Node error object you can catch through promise easily.
Last modified 3yr ago