Giter Site home page Giter Site logo

mowr's Introduction

Mowr ๐Ÿ˜บ makes using the Mongo client more comfy

npm GitHub file size in bytes
A very thin convenience wrapper for the Mongo client.

Installation

npm i mowr

Usage

const db = require('mowr')('localhost:27017/test', options)
const collection = db.get('collection')

const collection = require('mowr')('localhost/test', options).get('collection')

Supported calls

collection.find(query, options)    // returns array
collection.findc(query, options)   // returns cursor
collection.findOne(query, options) // returns object

collection.insert(object/array, options) // returns inserted object/array
collection.insertOne(object, options)    // returns inserted object
collection.insertMany(array, options)    // returns inserted array

collection.updateOne(query, update, options)  // -> {n: 1, nModified: 1, ok: 1}
collection.updateMany(query, update, options) // -> {n: 5, nModified: 5, ok: 1}
collection.replaceOne(query, update, options) // -> {n: 1, nModified: 1, ok: 1}

collection.deleteOne(query, options)  // -> {n: 1, ok: 1}
collection.deleteMany(query, options) // -> {n: 5, ok: 1}

collection.findOneAndUpdate(query, update, options)  // returns original document
collection.findOneAndReplace(query, update, options) // returns original document
collection.findOneAndDelete(query, options)          // returns deleted document

Options are always optional, and passed as object.

When connecting, 'mongodb://' is prepended if needed, and useUnifiedTopology is set to true (pass it as option to set it to false).

The query field can be an _id string (it will be converted to {_id: <ObjectID>}) or a query object.

Depending on if an object or array is passed in, insert will call insertOne or insertMany.

If an update object contains an _id property, even if nested, it will be removed.

When passing options using find, findc, findOne, make sure to use a query (can be {}).


Thanks to @fuzetsu for his invaluable help!

mowr's People

Contributors

osban avatar dependabot[bot] avatar

Stargazers

Daniel Loomer avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.