Socket
Book a DemoInstallSign in
Socket

dbdjs.mongo

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dbdjs.mongo

MongoDB wrapper using mongoose with dbdjs.db-like API

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

DBDJS.Mongo

NPM Version NPM Downloads

Table Of Contents

About

A MongoDB wrapper using mongoose with dbdjs.db like API

Examples

Default Instance

const mongoose = require("mongoose")
const dbdmongo = require("dbdjs.mongo").default

mongoose.connect("mongodb://localhost:27017/database", {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    keepAlive: true
})

dbdmongo.createModel("main")

dbdmongo.set("main", "my_name", "Matthew")
dbdmongo.set("main", "my_house", "USA")

//etc

Custom Instance

const mongoose = require("mongoose")
const dbdmongo = require("dbdjs.mongo")

;(async () => {
    const instance = dbdmongo.create(await mongoose.createConnection("mongodb://localhost:27017/database", {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        keepAlive: true
    }))

    instance.createModel("main")

    dbdmongo.set("main", "my_name", "Matthew")
    dbdmongo.set("main", "my_house", "USA")

    //etc
})

API

Module

  • default
    • Default dbdjs.mongo instance
    • Type: Instance
const dbdmongo = require("dbdjs.mongo").default
const dbdmongo = require("dbdjs.mongo").create(await mongoose.createConnection(
    "mongodb://localhost:27017/database", {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    keepAlive: true
}))

Instance

  • setInstance(mongoInstance)
    • Set a mongo instance to the dbdjs.mongo instance
    • Paramaters
    • Return: void
dbdmongo.setInstance(await mongoose.createConnection(
    "mongodb://localhost:27017/database", {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    keepAlive: true
}))
  • createModel(name)
    • Create a model to the dbdjs.mongo instance
    • Parameters
      • name: string
    • Return: void
dbdmongo.createModel("main")
  • getModel(name)
    • Get a model from the dbdjs.mongo instance
    • Parameters
      • name: string
    • Return: Model
dbdmongo.getModel("main")
  • deleteModel(name)
    • Delete a model from the dbdjs.mongo instance
    • Parameters
      • name: string
    • Return: void
dbdmongo.deleteModel("main")
  • set(model, key, value)
    • Set a data to the model
    • Parameters
      • model: string
      • key: string
      • value: any
    • Return: boolean
dbdmongo.set("main", "my_name", "Matthew")
  • get(model, key)
    • Get a data from the model
    • Parameters
      • model: string
      • key: string
    • Return: { key: string, value: any }
dbdmongo.get("main", "my_name")
  • all(model, options)
    • Get all data from the model and filter it
    • Parameters
      • model: string
      • options: object
        • filter: (document: { key: string, data: any }) => boolean
    • Return: Array<{ key: string, data: any }>
dbdmongo.all("main", { filter: d => d.data === "Matthew" })
  • delete(model, key)
    • Delete a data from the model
    • Parameters
      • model: string
      • key: string
    • Return: boolean
dbdmongo.delete("main", "my_name")

Keywords

mongodb

FAQs

Package last updated on 10 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts