1.0.9 • Published 5 years ago

mongodb-plus v1.0.9

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

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:

methodparameterway
insertinsert(collection,data)Based on Promise
insertSyncinsertSync(collection,data,callback)native-based
insertOneinsertOne(collection,data)Based on Promise
insertOneSyncinsertOneSync(collection,data,callback)native-based
insertManyinsertMany(collection,data)Based on Promise
insertManySyncinsertManySync(collection,data,callback)native-based
findfind(collection,data,limitValue,skipValue,sort)Based on Promise
findSyncfindSync(collection,data,callback,limitValue,skipValue,sort)native-based
findOnefindOne(collection,data)Based on Promise
findOneSyncfindOneSync(collection,data,callback)native-based
updateOneupdateOne(collection,data1,data2)Based on Promise
updateOneSyncupdateOneSync(collection,data1,data2,callback)native-based
updateManyupdateMany(collection,data1,data2)Based on Promise
updateManySyncupdateManySync(collection,data1,data2,callback)native-based
deleteOnedeleteOne(collection,data)Based on Promise
deleteOneSyncdeleteOneSync(collection,data,callback)native-based
deleteManydeleteMany(collection,data)Based on Promise
deleteManySyncdeleteManySync(collection,data,callback)native-based
deleteCollectiondeleteCollection(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**
1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago