siwi-mongodb

nodejs 连接 mongodb

Usage no npm install needed!

<script type="module">
  import siwiMongodb from 'https://cdn.skypack.dev/siwi-mongodb';
</script>

README

siwi-mongodb

nodejs 连接 mongodb

const MongoDb = require('../index')
const url = 'mongodb://192.168.0.102:27017'
const db = 'siwi-wget' 
const mongodb = new MongoDb(url, db)
const ObjectId = mongodb.ObjectId  
class Test {
    constructor() {
        this.init()
    }
    async init () {
        const mongo = await mongodb.MongoClient()
        const coll = await mongo.collection('test')
        const res = await coll.find({_id: ObjectId("5aa1841a4290b52ce4c53e66")}).toArray()
        console.log(res)
    }
}

module.exports = new Test()