npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongodb-plus

v1.0.9

Published

This is a wrapper library for the mongodb method that makes it easier for nodes to manipulate the mongodb database.

Downloads

25

Readme

Introduction mongodb-plus

  • This is a plugin that was created to make it easy to operate the mongodb database in nodejs,Maybe everyone has heard of mongoose, indeed mongoose is also very good, but there are model objects in mongoose that limit the input data. I don't like this limitation very much, so I created this plugin 23333.
  • I am encapsulating based on the native method of mongodb,It is highly compatible with the original method, but it is more convenient,The method is named the same as the native method, so that you can get started directly,The method I divided into two types:One is an improved native method (with Sync ending)The other is based on Promise encapsulation (without Sync),Can be used in conjunction with async asynchronous function (comfortable with koa)
  • This plugin is essentially a syntactic sugar,Is that you can use nodejs to operate the mongodb database more convenient,But essentially the native mongodb method, so there is no change in performance

Use of mongodb-plus

1. installation

npm i mongodb-plus

2. Connect mongodb
//import mongodb-plus
const db = require("mongodb-plus")
//The way to connect to the database is the same as the native,I don't make too many changes here
db.connect("mongodb://localhost:10086/demo1").then(()=>{
    console.log("connected...")
}).catch(err=>{
    console.log(err)
})

3. For the use of the method, see the table below:

|method|parameter|way| |---|---|---| |insert|insert(collection,data)|Based on Promise| |insertSync|insertSync(collection,data,callback)|native-based| |insertOne|insertOne(collection,data)|Based on Promise| |insertOneSync|insertOneSync(collection,data,callback)|native-based| |insertMany|insertMany(collection,data)|Based on Promise| |insertManySync|insertManySync(collection,data,callback)|native-based| |find|find(collection,data[,limitValue,skipValue,sort])|Based on Promise| |findSync|findSync(collection,data,callback[,limitValue,skipValue,sort])|native-based| |findOne|findOne(collection,data)|Based on Promise| |findOneSync|findOneSync(collection,data,callback)|native-based| |updateOne|updateOne(collection,data1,data2)|Based on Promise| |updateOneSync|updateOneSync(collection,data1,data2,callback)|native-based| |updateMany|updateMany(collection,data1,data2)|Based on Promise| |updateManySync|updateManySync(collection,data1,data2,callback)|native-based| |deleteOne|deleteOne(collection,data)|Based on Promise| |deleteOneSync|deleteOneSync(collection,data,callback)|native-based| |deleteMany|deleteMany(collection,data)|Based on Promise| |deleteManySync|deleteManySync(collection,data,callback)|native-based| |deleteCollection|deleteCollection(collection)|native-based|

4. for example

const db = require("mongodb-plus")
//db.connect("mongodb://localhost:10086/demo1")
db.connect("mongodb://localhost:10086/demo1").then(()=>{
    console.log("connected...")
}).catch(err=>{
    console.log(err)
})

//Use the native-based method findSync
db.findSync("people",{},data=>{
    console.log(data)
})
//Use the Promise-based method find
db.find("people",{}).then(data=>{
    console.log(data)
}).catch(err=>{
    console.log(err)
})

//You can also use it with async asynchronous functions
async function show(){
    const data = await db.find("people",{})
    console.log(data)
}
show()

//insert
db.insert("people",{ username:"laowang", password:"lw12345" }).then(result=>{
    console.log(result)
}).catch(err=>{
    console.log(err)
})

//Or use insertSync
db.insertSync("people",{ username:"laodi", password:"ld12345" },function(){
    console.log("insert successful...")
})
  • mongodb-plus allows you to operate mongodb using node and become very free and simple,Want to know more can look at the following address:

npm: https://www.npmjs.com/package/mongodb-plus

github: https://github.com/shataniya/mongodb-plus