简体   繁体   English

保存操作不起作用

[英]Save operation not working

I am trying to perform save a collection in mongo db using the node.js driver.I use the following code: 我正在尝试使用node.js驱动程序在mongo db save集合。我使用以下代码:

 require("mongodb").MongoClient.connect("mongodb://localhost:27017/course",function(db,err){
if(err) console.log(err);
else{
    var query={"assignment":"hw2"};
    db.collection("grades").findOne(query,function(err,doc){
        if(err) console.log(err);
        else{
            //console.dir(doc);
            doc["date_returned"]=new Date();
            db.collection("grades").save(doc,function(err,saved){
                if(err) console.log(err);
                else{
                    console.log("Successfully saved "+saved+" documents");
                    return db.close();
                }

            });
        }

    });
}

}); });

I get this huge error which I put in this pastebin 我收到了这个巨大的错误,将其放入了pastebin中

There is a typo in the callback of the .connect function. .connect函数的回调中有一个错字。 You exchanged the error with the result in the argument positions, so you are printing the database object instead the error. 您将错误与结果交换在参数位置中,因此您正在打印数据库对象而不是错误。 It should be: 它应该是:

.connect("mongodb://localhost:27017/course",function(err,db){

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM