Created
October 4, 2016 07:10
-
-
Save asvid/0ebdfa67b3f630a0c99c05f63b6120da to your computer and use it in GitHub Desktop.
MongoDB save or update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var query = {ean: productJson.ean}, | |
options = {upsert: true, new: true, setDefaultsOnInsert: true}; | |
Product.findOneAndUpdate(query, productJson, options, function (error, item) { | |
if (!!error) { | |
res.status(400).json(error) | |
} else { | |
res.status(201).json({"msg": "document created"}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment