4

How do I update a mongodb collection from JS?

db.collection('fruits', function (err, collection) {
    collection.update({ "_id": content.fruitID}, content, function () {
    });
});

Am I doing this right? DO I need to use $set?

Basically content is a json object that should replace the document that's found.

Thanks.

I'm using the mongodb node native driver.

1 Answer 1

2

If you want to replace the document you're doing the right thing. If you want to update a field of the existing document you should use $set.

See here: http://www.mongodb.org/display/DOCS/Updating

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.