I reset my database every night with a mongoimport command. Unfortunately, I understand that it drops the database first then fills it again.
This means that my database is being queried while half-filled. Is there a way to make the mongoimport atomic ? This would be achieved by first filling another collection, dropping the first then renaming the second.
Is that a builtin feature of mongoimport ?
Thanks,
It's unclear what behaviour you want from your nightly process.
If your nightly process is responsible for creating a new dataset then dropping everything first makes sense. But if your nightly process is responsible for adding to an existing dataset then that might suggest using
mongorestore
(without--drop
) sincemongorestore
's behaviour is:However, those concerns seem to be secondary to your need to import / restore into your database while it is still in use. I don't think either
mongoimport
ormongorestore
are viable 'write mechanisms' for use when your database is online and available for reads. From your question, you are clearly aware that issues can arise from this but there is no Mongo feature to resolve this for you. You can either:Take your system offline during the
mongoimport
ormongorestore
and then bring it backonline once that process is complete and verifiedUse
mongoimport
ormongorestore
to create a side-by-side database and then once this database is ready switch your application to read from that database. This is a variant of a Blue/Green or A/B deployment model.