var mongo = require("mongodb").MongoClient;
var url = "mongodb://127.0.0.1:27017/test3";
function insertOne(collection, obj, callBack){ //单个插入
mongo.connect(url, function (error, db) {
if (error == null) {
var database = db.db("test3");
database.collection(collection).insertOne(obj, callBack)
} else {
console.log(error)
}
db.close();
})
}
function insertMany(collection, objArr, callBack){ //多个插入
mongo.connect(url, function (error, db) {
if (error == null) {
var database = db.db("test3");
database.collection(collection).insertMany(objArr, callBack)
} else {
console.log(error)
}
db.close();
})
}
function find(collection, where, callBack){ // 查询
mongo.connect(url, function (error, db) {
if (error ==&#
封装nodejs对MongoDB的增、删、改、查
最新推荐文章于 2022-02-21 17:03:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)