Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodump/mongorestore from NodeJS or mongoose

Wondering if it is possible to run mongodump/mongorestore from within nodejs. Probably not really a mongoose thing as that is not really what mongoose is for. But wondering if there is a way to execute these command from the mongodb nodejs driver.

Looks like I can do this as a last resort: How do I execute the mongodump command programmatically from node.js?

like image 782
lostintranslation Avatar asked Mar 23 '13 15:03

lostintranslation


2 Answers

When you say 'from node.js' I assume you mean calling the mongodump/mongostore command from your node.js application.

Since mongodump and mongostore are command line applications. The only way you can "execute them" from node.js is to use the solution you already found here.

That is, using child_process.spawn since no-one has created a node.js binding for them yet.

I would not use it as "a last resort" since it does exactly what you need. However, I should mention you can implement backing-up and restoring mongodb data yourself pretty easily with the node.js driver. That is, iterate through the collections and store them, do the reverse for restoring a back up.

I strongly suggest against it though. The problem with the approach suggested in the question you linked to is relatively minor. I've seen it used (well, something similar) in production myself and there were no issues.

like image 135
Benjamin Gruenbaum Avatar answered Sep 25 '22 19:09

Benjamin Gruenbaum


I've written a tiny module to this: https://github.com/meryn/mongo-utils . It parses the mongo connection string for you.

like image 24
Myrne Stol Avatar answered Sep 25 '22 19:09

Myrne Stol