Mod Meteor application - how to reset a database

I am running a phased Meteor application on Modulus and would like to know if there is a way to do something similar to "meteor reset" on a remote mongoDB.

I can use the mongo command line by running db.dropDatabase(); , but it also removes system.users , which contains the mongo database accounts.

Interested in how this can be achieved in the deployment stream.

+5
source share
3 answers

When you run meteor reset , then the meteor recursively deletes all files and files from: .meteor/local .

  # source : meteor/tools/commands.js (line 806-807) ... var localDir = path.join(options.appDir, '.meteor', 'local'); files.rm_recursive(localDir); ... 

I understand that you want to delete specific collections from a database stored in MongoDB. There are several ways to do this:

Remove collections from mongo shell or shell

Write a script that iterates over the names of the collections you want to delete, and then run db.getCollection(name).drop() on each of them.

From cmd: mongo [database] --eval "db.getCollection ([collectionName]). Drop ();"

or from mongo shell:

 db.getCollection([collectionName]).drop(); 

Delete collections from MongoDB using Robomongo

This is a simple method: click and delete.

Useful note if you can connect to the mongo server using ssh:

If you have SSH access to the server where mongo is located, you can tunnel the remote port Y to local port X, so mongo will be available locally on port X:

 ssh -L27018:localhost:27017 user@host 

Then in Robomongo you create a connection with localhost: 27018 and you have access to the remote db.

Delete collections directly from the Meteor app.

 if(Meteor.isServer){ Collection.remove({}) } 

One of my production applications deletes some collections when deploying a new version:

  if(Meteor.isServer){ Meteor.startup(function(){ if(cleanDB){ CollectionA.remove({}); CollectionB.remove({}); CollectionC.remove({}); } }) } 
+7
source

If you want to use the MongoDB shell for the module:

 db.getCollectionNames().forEach(function(name) { if (name.indexOf('system.') === -1) { db.getCollection(name).drop(); } }) 

Use the Robomongo application to connect and execute this or on the command line:

 mongo <dbname> --host proximus.modulusmongo.net:27017 --username <username> --password <password> --eval "db.getCollectionNames().forEach(function(name) {if (name.indexOf('system.') === -1) {db.getCollection(name).drop();}})" 
+1
source

I believe that the easiest way to do this on modulus.io is to access your database and delete the collection that you want to get rid of.

run the following command in the terminal $ mongo waffle.modulusmongo.net:27017/izezeB9a -u DB_UserName -p Password

when you connect to your db then release this collection:> db.YourCollection.drop()

hope this helps

cheers;)

+1
source

Source: https://habr.com/ru/post/1200175/


All Articles