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:
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();
This is straightforward method : click and remove.
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.
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();}})"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With