These are chat archives for Automattic/mongoose

Aug 2017
Aug 02 2017 06:19
I am new to mongoose. I need to update a collection, while i update every time, all the previous data in the collection needs to deleted, and new data needs to be saved afresh.
can anyone guide
Paul "Joey" Clark
Aug 02 2017 14:49

@aalokit You can use findOneAndUpdate() with {upsert: true} to update and/or create new documents, but that won't remove any documents.

Or you could just remove the entire collection before you start, with: model.collection.drop()
I imagine the collection will re-appear the next time you create a new document.