Saturday 10 June 2017

The website could not load when i changed the parameter in updateOne()

I was trying to made a login in page. I use method "updateOne" to match the information given by users since i do not know any other method that i can use to make a judgement whether the account number is right or not.( can somebody tell me how ? i feel "findOne()" can do this job but i do not know how to use it.)

here is the code:

router.post('/update', function(req, res, next) {
var item = {
    title: req.body.title,
    content: req.body.content,
    author: req.body.author
};

mongo.connect(url, function(err, db) {
    assert.equal(null, err);
    db.collection('user-data').updateOne({"title": req.body.title , "content": req.body.content}, {$set: item}, function(err, result) {
        assert.equal(null, err);
        console.log('Item updated');
        db.close();

    });
});
});

this one works. Things updated well but i have to refresh the website or it just keep loading. keep loading

the original code is:original code

i just changed the id to something else. but the original one works well, which means i dont have to refresh the website myself.



via 马露月

No comments:

Post a Comment