I'm pulling data from a RETS(XML) feed and saving it in a local MongoDB using node and mongoose.
Periodically I need to update the documents and delete the inactive ones as well as add new ones. Rather than making multiple queries to Mongo or the RETS server, I was pulling both and looping through the data.
This works fine but is there a way to save the Mongoose results back to the database with updates and inserts? Or do I need to find each document and update it individually?
To update multiple documents (not just one) on MongoDB using Mongoose you can use the multi option:
Model.update({
field_that_matches_many_docs: ninja_variable
}, {
$set: { size: 'large' }
}, {
multi: true
}, callback);
See more on in the Mongoose documentation for updating documents and here