vamsiampolu
vamsiampolu

Reputation: 6622

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:

 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

Upvotes: 0

Views: 65

Answers (1)

durum
durum

Reputation: 3404

There is a typo in the callback of the .connect function. 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){

Upvotes: 1

Related Questions