All Projects → mono-js → Mongodb Utils

mono-js / Mongodb Utils

Licence: mit
MongoDB utils library for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mongodb Utils

Node Express Boilerplate
A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose
Stars: ✭ 890 (+9788.89%)
Mutual labels:  mongodb
Webhubbot Downloader
Download videos from xiyouMc's WebHubBot.
Stars: ✭ 24 (+166.67%)
Mutual labels:  mongodb
We Voting
🙋 A Voting App based on React + Express + Mongodb
Stars: ✭ 26 (+188.89%)
Mutual labels:  mongodb
Pokedexvuejs
A Pokedex that will contain all 807 pokemon from the Pokemon series. Created in Vue.js
Stars: ✭ 19 (+111.11%)
Mutual labels:  mongodb
Golang Sse Todo
golang server sent events (sse) example
Stars: ✭ 23 (+155.56%)
Mutual labels:  mongodb
Jetbrains Webcast Build With Mongodb
Code and handouts for my JetBrains webcast recorded January 30, 2018
Stars: ✭ 25 (+177.78%)
Mutual labels:  mongodb
M Mall Admin
🐶 微信小程序-小商城后台(基于 Node.js、MongoDB、Redis 开发的系统...)
Stars: ✭ 895 (+9844.44%)
Mutual labels:  mongodb
Spm Agent Mongodb
Sematext Agent for monitoring MongoDB
Stars: ✭ 7 (-22.22%)
Mutual labels:  mongodb
Mean Angular5 Passport Authentication
Securing MEAN Stack (Angular 5) Web Application using Passport Authentication
Stars: ✭ 24 (+166.67%)
Mutual labels:  mongodb
Javascript Fullstack Simple
Follow this tutorial using this link
Stars: ✭ 26 (+188.89%)
Mutual labels:  mongodb
Mondocks
An alternative way to interact with MongoDB databases from F# that allows you to use mongo-idiomatic constructs
Stars: ✭ 20 (+122.22%)
Mutual labels:  mongodb
Myjdbc Rainbow
jpa--轻量级orm模式对象与数据库映射api
Stars: ✭ 23 (+155.56%)
Mutual labels:  utils
Express Boilerplate
A fast, simple Node.js/Express + MongoDB + Vue.js web app boilerplate project
Stars: ✭ 25 (+177.78%)
Mutual labels:  mongodb
Mevn Stack
Stars: ✭ 19 (+111.11%)
Mutual labels:  mongodb
Mongo Connector Postgresql
River from Mongo oplog to postgresql
Stars: ✭ 26 (+188.89%)
Mutual labels:  mongodb
Mongodb Backup Cli
mongodb-backup cli for Nodejs
Stars: ✭ 17 (+88.89%)
Mutual labels:  mongodb
Reactjs Portfolio Mern Website
My Portfolio | Full Stack MERN Application
Stars: ✭ 25 (+177.78%)
Mutual labels:  mongodb
Springbootunity
rabbitmq、redis、scheduled、socket、mongodb、Swagger2、spring data jpa、Thymeleaf、freemarker etc. (muti module spring boot project) (with spring boot framework,different bussiness scence with different technology。)
Stars: ✭ 845 (+9288.89%)
Mutual labels:  mongodb
Awesome Javascript Interviews
Popular JavaScript / React / Node / Mongo stack Interview questions and their answers. Many of them, I faced in actual interviews and ultimately got my first full-stack Dev job :)
Stars: ✭ 939 (+10333.33%)
Mutual labels:  mongodb
Subnode.org
SubNode: Social Media App
Stars: ✭ 25 (+177.78%)
Mutual labels:  mongodb

MongoDB Utils

MongoDB utils for Node.js

npm version Travis Coverage license

Installation

npm install --save mongodb-utils

Usage

MongoDB utils overide the collection class by adding an utils object that will expose all the MongoDB utils methods:

const mongoUtils = require('mongodb-utils')

const collection = mongoUtils(db.collection('users'))

// We can now access to mongodb-utils method from .utils
const user = await collection.utils.get({ username: 'terrajs' })

Methods

get

get(query = { key: value } || string || ObjectID, [fields]): Promise<doc>

Return a document that match the specific identifier (_id by default) or the query:

// Get the document that match the query { _id: ObjectID('59c0de2dfe8fa448605b1d89') }
collection.utils.get('59c0de2dfe8fa448605b1d89')

// Get the document that match the query { username: 'terrajs' }
collection.utils.get({ username: 'terrajs' })

// Get the document that match the query & return only its _id
collection.utils.get({ username: 'terrajs' }, { _id: 1 })
// Get the document that match the query & return only its _id (works with array too)
collection.utils.get({ username: 'terrajs' }, ['_id'])

create

create(doc: object): Promise<doc>

Insert a document into the collection and add createdAt and updatedAt properties:

// Add a document into the collection and return the created document
const user = await collection.utils.create({ username: 'terrajs' })

update

update(query = { key: value } || string || ObjectID, doc: object): Promise<doc>

Update a specific document and update the updatedAt value

// Update the document that match the query { _id: ObjectID('59c0de2dfe8fa448605b1d89') } and update its username
await collection.utils.update('59c0de2dfe8fa448605b1d89', { username: 'terrajs2' })

// Update the document that match the query { username: 'terrajs2' } and update its username
await collection.utils.update({ username: 'terrajs2' }, { username: 'terrajs' })

upsert

upsert(query = { key: value } || string || ObjectID, doc: object): Promise<doc>

Update or create a document if not exist Add the createdAt if document not exist

// Update the document that match the query { _id: ObjectID('59c0de2dfe8fa448605b1d89') } and update its username or create it if not exist
await collection.utils.upsert('59c0de2dfe8fa448605b1d89', { username: 'terrajs2' })

// Update the document that match the query { username: 'terrajs2' } and update its username OR create it if not found
await collection.utils.upsert({ username: 'terrajs2' }, { username: 'terrajs' })

remove

remove(query = { key: value } || string || ObjectID): Promise<boolean>

Remove a document that match the specific identifier (_id by default) or the query:

// Remove the document that match the query { _id: ObjectID('59c0de2dfe8fa448605b1d89') }
const result = collection.utils.remove('59c0de2dfe8fa448605b1d89')

// Remove the document that match the query { username: 'test' }
collection.utils.remove({ username: 'test' })

find

find(query = { key: value } || string || ObjectID, [options = { fields: ..., limit: ..., offset: ..., sort: ... }]): cursor

The find method return a mongo cursor from a specific query and options.

Options:

  • fields: Array of keys (['username', ...]) to return OR a MongoDB projection ({ field1: 1, ... }), default: {}
  • limit: Nb of docs to return, no limit by default
  • offset: Nb of docs to skpi, default: 0
  • sort: Sort criteria (same as sort method from mongo cursor), default: {}
// Find documents that matches the query { username: new RegExp(/^test/g) }, options with { username: 1, createdAt: 1 } projection and limit at 10 elements
const users = await userCollection.mono.find({
  username: new RegExp(/^test/g)
}, {
  fields: ['username', 'createdAt'],
  limit: 10
}).toArray()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].