一、向mongodb数据库添加一条数据
insertOne
/models/index.jsconst { MongoClient} = require('mongodb');// Connection URLconst url = 'mongodb://124.71.174.116:10040';const client = new MongoClient(url);const dbName = 'Student';async function main() {await client.connect();console.log('Connected successfully to server');const db = client.db(dbName);const collection = db.collection('member');return collection;}module.exports = main;
router.get("/add",async ctx=>{
var collection = await main();
var obj = {
name:"吴章",
age:17
}
var res = await collection.insertOne(obj);
console.log(res)
})
