简体   繁体   中英

Meteor app on Modulus — how to reset database

I'm running a staged Meteor app on Modulus and would like to know if there's a way to do something similar to 'meteor reset' on the remote mongoDB.

I could use mongo's command line by running db.dropDatabase(); however this also removes system.users which contains the mongo database accounts.

Interested to know how this can be achieved in the flow of deploying.

When you run meteor reset then meteor recursively removes all dirs 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 would like to remove particular collections from database stored in MongoDB. There are few ways of doing that:

Remove collections from shell or mongo shell

Write script which loops over names of collections you want to drop and then execute db.getCollection(name).drop() on each one.

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

or from mongo shell:

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

Remove collections from MongoDB using Robomongo

This is straightforward method : click and remove.

Helpful note if one can connect to mongo's server with ssh:

If you have SSH access to server where is mongo then you can tunnel 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 connection to localhost:27018 and you have access to remote db.

Remove collections directly from Meteor App.

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

One of my production app removes some collections when new version is deployed:

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

If you'd like to use the MongoDB shell on Modulus:

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

Use the Robomongo app 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();}})"

I believe the easiest way of doing this on modulus.io would be to access your database and drop the collection 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 connected to you DB, then drop that collection running: > db.YourCollection.drop()

hope this helps,

cheers ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM