PeakDB
  • Introduction
  • Quick Start
  • Change Log
  • Reference
    • Bitwise Permission Flags
    • Supported Node.js Versions
    • NPM
    • GitHub
  • Constructors
    • Server
    • Connection
    • Collection
  • Classes
    • Collection
      • createBackup
      • loadBackup
      • drop
    • DocumentBasedCollection
      • insert
      • find
      • filter
      • has
      • update
      • archive
      • unarchive
      • delete
    • KeyValueBasedCollection
      • set
      • get
      • push
      • remove
      • find
      • filter
      • has
      • increase
      • decrease
      • delete
Powered by GitBook
On this page
  • insert(document)
  • find(params, options)
  • filter(params, options)
  • has(params, options)
  • update(document_id, document)
  • archive(document_id)
  • unarchive(document_id)
  • delete(document_id)
  1. Classes

DocumentBasedCollection

Methods for document-based collections.

insert(document)

Insert a document.

Parameter
Description

document

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.

Parameter
Description

params

options

options.archived

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.

Parameter
Description

params

options

options.archived

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.

Parameter
Description

params

options

options.archived

returns Boolean

Example:

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

update(document_id, document)

Update a document.

Parameter
Description

document_id

document

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.

Parameter
Description

document_id

returns Boolean

Example:

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

unarchive(document_id)

Unarchive a document.

Parameter
Description

document_id

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.

Parameter
Description

document_id

returns Boolean

Example:

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

Last updated 3 years ago

The document to be written to the collection.

| The parameters you will use to find the data.

(optional) Find options.

(optional) Whether to find archived documents.

| The parameters you will use to filter the data.

(optional) Filter options.

(optional) Whether to filter archived documents.

| The parameters you will use to check the data.

(optional) Find options.

(optional) Whether to has archived documents.

The ID of the document to be updated.

The document to be updated in the collection.

The ID of the document to be archived.

The ID of the document to be unarchived.

The ID of the document to be deleted.

Object
Function
Object
Object
Boolean
Function
Object
Object
Boolean
Function
Object
Object
Boolean
String
Object
String
String
String