DocumentBasedCollection

Methods for document-based collections.

insert(document)

Insert a document.

ParameterDescription

document

Object The document to be written to the collection.

returns Object

Example:

accounts.insert({"email": "fir4tozden@gmail.com", "username": "fir4tozden", "password": "12345678", "region": "Muğla"});
/*
  {
    "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
    "_updated": false,
    "_archived": false,
    "_created_at": 2022-03-20T00:00:00.000Z,
    "_created_timestamp": 1647745200000,
    "email": "fir4tozden@gmail.com",
    "username": "fir4tozden",
    "password": "12345678",
    "region": "Muğla"
  }
*/

find(params, options)

Find a document.

ParameterDescription

params

Function | Object The parameters you will use to find the data.

options

Object (optional) Find options.

options.archived

Boolean (optional) Whether to find archived documents.

returns Object

Example:

accounts.find(document => document.email === "fir4tozden@gmail.com", {"archived": true});
// or
accounts.find({"email": "fir4tozden@gmail.com"}, {"archived": true});
/*
  {
    "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
    "_updated": false,
    "_archived": false,
    "_created_at": 2022-03-20T00:00:00.000Z,
    "_created_timestamp": 1647745200000,
    "email": "fir4tozden@gmail.com",
    "username": "fir4tozden",
    "password": "12345678",
    "region": "Muğla"
  }
*/

filter(params, options)

Filter documents.

ParameterDescription

params

Function | Object The parameters you will use to filter the data.

options

Object (optional) Filter options.

options.archived

Boolean (optional) Whether to filter archived documents.

returns Array<Object>

Example:

accounts.filter(document => document.region === "Muğla", {"archived": true});
// or
accounts.filter({"region": "Muğla"}, {"archived": true});
/*
  [
    {
      "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
      "_updated": false,
      "_archived": false,
      "_created_at": 2022-03-20T00:00:00.000Z,
      "_created_timestamp": 1647745200000,
      "email": "fir4tozden@gmail.com",
      "username": "fir4tozden",
      "password": "12345678",
      "region": "Muğla"
    },
    {
      "_id": "23ERK9fHqiH_n83fhzU7eOYtzz6tUl7S",
      "_updated": false,
      "_archived": false,
      "_created_at": 2022-03-20T00:05:00.000Z,
      "_created_timestamp": 1647734700000,
      "email": "nehir@gmail.com",
      "username": "nehir",
      "password": "12345678",
      "region": "Muğla"
    }
  ]
*/

has(params, options)

Check if they have document.

ParameterDescription

params

Function | Object The parameters you will use to check the data.

options

Object (optional) Find options.

options.archived

Boolean (optional) Whether to has archived documents.

returns Boolean

Example:

accounts.has(document => document.region === "Muğla"); // -> true
accounts.has({"region": "Muğla"}); // -> true

update(document_id, document)

Update a document.

ParameterDescription

document_id

String The ID of the document to be updated.

document

Object The document to be updated in the collection.

returns Object

Example:

let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
accounts.update(document._id, {"email": "fir4tozden@gmail.com", "username": "hey_im_fir4tozden", "password": "87654321", "region": "İstanbul"});
/*
  {
    "_id: "23ERK9fHqiH_n83fhzU7eOYtzz6tUl7S",
    "_updated": true,
    "_archived": false,
    "_created_at": 2022-03-20T00:00:00.000Z,
    "_created_timestamp": 1647745200000,
    "_updated_at": 2022-03-20T00:10:00.000Z,
    "_updated_timestamp": 1647735000000,
    "email": "fir4tozden@gmail.com",
    "username": "hey_im_fir4tozden",
    "password": "87654321",
    "region": "İstanbul"
  }
*/

archive(document_id)

Archive a document.

ParameterDescription

document_id

String The ID of the document to be archived.

returns Boolean

Example:

let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
accounts.archive(document._id); // -> true

unarchive(document_id)

Unarchive a document.

ParameterDescription

document_id

String The ID of the document to be unarchived.

returns Boolean

Example:

let document = accounts.find(document => document.email === "fir4tozden@gmail.com", {"archived": true});
accounts.unarchive(document._id); // -> true

delete(document_id)

Delete a document.

ParameterDescription

document_id

String The ID of the document to be deleted.

returns Boolean

Example:

let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
accounts.delete(document._id); // -> true

Last updated