These are chat archives for Automattic/mongoose

2nd
Aug 2017
aalokit
@aalokit
Aug 02 2017 06:19
Hi,
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
@joeytwiddle
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.