在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:nswbmw/koa-mongo开源软件地址:https://github.com/nswbmw/koa-mongo开源编程语言:JavaScript 100.0%开源软件介绍:koa-mongokoa-mongo is a mongodb middleware for koa@2, support connection pool. Installnpm i koa-mongo --save Usageapp.use(mongo({
host: 'localhost',
port: 27017,
user: 'admin',
pass: '123456',
db: 'test',
authSource: 'admin',
max: 100,
min: 1,
...
})); or app.use(mongo({
uri: 'mongodb://admin:123456@localhost:27017/test?authSource=admin', //or url
max: 100,
min: 1
...
})); or app.use(mongo({
uri: 'mongodb://admin:123456@localhost:27017/test?authSource=admin', //or url
max: 100,
min: 1
...
}, {
useUnifiedTopology: true
...
}
)); defaultOptions: {
host: 'localhost',
port: 27017,
db: 'test',
authSource: 'admin',
max: 100,
min: 1,
acquireTimeoutMillis: 100
} More options see generic-pool. ctx.mongo & ctx.db
ctx.db === ctx.mongo.db(dbName) Exampleconst Koa = require('koa')
const mongo = require('koa-mongo')
const app = new Koa()
app.use(mongo())
app.use(async (ctx, next) => {
// ctx.db === ctx.mongo.db('test')
const result = await ctx.db.collection('users').insert({ name: 'haha' })
const userId = result.ops[0]._id.toString()
ctx.body = await ctx.db.collection('users').find().toArray()
ctx.db.collection('users').remove({
_id: mongo.ObjectId(userId)
})
})
app.listen(3000, () => {
console.log('listening on port 3000')
}) MongolassMongolass is a elegant MongoDB driver for Node.js. LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论