首页 > 数据库技术 > 详细

mongodb 3.x以上版本与mongodb 2.x版本语法区别

时间:2020-02-07 15:22:49      阅读:93      评论:0      收藏:0      [点我收藏+]

2.x

const MongoClient = require(‘mongodb‘).MongoClient;
const url = ‘mongodb://localhost:27017/test‘;
MongoClient.connect(url, function (err, db) {
if (err) throw new Error(err);
db.collection(‘myCollection‘).updateOne({ // Update method ‘updateOne‘
greetings: "Hellu" },
{ $set: { greetings: "Whut?" }},
function (err, result) {
if (err) throw new Error(err);
db.close(); // Don‘t forget to close the connection when you are done
});
});

3.x

const MongoClient = require(‘mongodb‘).MongoClient;

const url = ‘mongodb://localhost:27017/wang‘;

MongoClient.connect(url, function(err, client) {
    if(err) throw new Error(err);
    var db = client.db(‘wang‘);
    db.collection(‘myCollection‘).updateOne({ // Update method ‘updateOne‘
    greetings: "Hellu" },{ $set: {greetings: "Whut?"}},
                        function(err,result) {
                        if(err) throw new Error(err);
                        client.close(); // Don‘t forget to close the connection when you are done
                        });
});
                        
                        
                       

 

mongodb 3.x以上版本与mongodb 2.x版本语法区别

原文:https://www.cnblogs.com/lishidefengchen/p/12272688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!