@xorb/mongo
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Mongo

Minimal MongoDB client.

Example usage

Prerequisites

  • npm or yarn
yarn add @xorb/mongo
 # or you can use
npm install @xorb/mongo --save

Usage

// index.js
import { mongo } from '@xorb/mongo'

async function initDatabase() {
  try {
    const uri = 'mongo://'
    const db = await mongo.connect(uri)
    // connected to database, do something is needed
    const data = await db.collection('todos').find()
  } catch {
    // Something went wrong
  }
}

// controller.js
import { mongo } from '@xorb/mongo'
async function createTodo() {
  try {
    const db = await mongo.getDb()
    const todo = { body: 'Hello world', completed: false }
    const res = db.collection('todos').insertOne(todo)
    // do more
  } catch {
    // handle errors
  }
}

Contribute

I would really like a comments. So you can fork this repository and leave a PR with comments. Thanks.

Author

Created and maintained by Dany Boza (@xorbmoon).

Readme

Keywords

none

Package Sidebar

Install

npm i @xorb/mongo

Weekly Downloads

15

Version

0.0.3

License

ISC

Unpacked Size

98.5 kB

Total Files

14

Last publish

Collaborators

  • xorb