dbdjs.mongo
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    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")

    Install

    npm i dbdjs.mongo

    DownloadsWeekly Downloads

    57

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    14.3 kB

    Total Files

    14

    Last publish

    Collaborators

    • xzusfin