Remove Mongo from EC2

I recently switched from using a local Mongo instance (deployed using mup) to using a remote instanced hosted on mlabs.

I migrated the data over and now want to remove the old database.

How would I safely go about removing the Mongo instance from EC2? Will this cause unintended issues using mup or Meteor?

Start by shutting it down to see if your app is working well and you properly repointed DB URL:

sudo service mongodb stop

(assuming you are using standard libs and it’s called mongodb)

Thank you.

I can see that the database on mlabs is getting new data and the local is not. By shutting down the service, will this delete the database and purge the data?

No, it just turns off he daemon, data stays as is. To remove the data you have to call

sudo apt-get purge mongodb

I ran this command:

$ sudo service mongod stop
mongod stop/waiting

Then this:

$ sudo apt-get purge mongod
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mongod

Just to see:

$ mongod
2016-08-10T19:33:07.565+0000 I CONTROL  [initandlisten] MongoDB starting : pid=777 port=777 dbpath=/data/db 64-bit host=ip-777-77-77-7777
2016-08-10T19:33:07.565+0000 I CONTROL  [initandlisten] db version v3.2.8
2016-08-10T19:33:07.565+0000 I CONTROL  [initandlisten] git version: 7777
2016-08-10T19:33:07.565+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 777 6 Jan 2014
2016-08-10T19:33:07.565+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2016-08-10T19:33:07.565+0000 I CONTROL  [initandlisten] modules: none
2016-08-10T19:33:07.565+0000 I CONTROL  [initandlisten] build environment:
2016-08-10T19:33:07.565+0000 I CONTROL  [initandlisten]     distmod: ubuntu1404
2016-08-10T19:33:07.566+0000 I CONTROL  [initandlisten]     distarch: x86_64
2016-08-10T19:33:07.566+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2016-08-10T19:33:07.566+0000 I CONTROL  [initandlisten] options: {}
2016-08-10T19:33:07.589+0000 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2016-08-10T19:33:07.589+0000 I CONTROL  [initandlisten] dbexit:  rc: 100

On the EC2 instance the app still runs fine so far.

Where are the MongoDB database files located, so I can make sure they’ve been removed?

sudo apt-get remove mongod

To find files search /etc/mongo for conf file


Searching the etc dir I see:


Why don’t you just start a new server? All config and deployment should be automated so it should be quite simple to start a new server, just like you would do when scaling?

Good idea. But there’s a lot more too it than that. I have many files and directories outside of the Meteor directory that have to be manually set up, with permissions etc. Also, I have to change the domain mappings etc. At some point I need to build a script to automate this.

Starting a new server every time there is a change seems overkill to me. Shutting down and removing pieces you don’t need seems faster.

I believe it’s a learning curve on how to admin Linux boxes, which can be quite steep.

You can say that again.

I found these two files in etc but I’m not sure if I should delete them or not:


Yeah, should really automate that. Makes it much easier to deal with this kind of situations. Especially if your data is not on the web server like you have now with mlab. Having local files can be ok but also might better be outsourced. Did you connect permanent storage to save those files?

@ramez yes it’s a learning curve and it’s tricky on a production machine, lots of risk added while processing the manual commands. Certainly when there is in general no need for it anymore.

Sorry, I wasn’t clear :slight_smile:

You can find in them the location of your db – that was your question, no?

If you want to make sure mongo is NOT running you can call this:

sudo service mongod status

It will tell you if it’s up or down (you may need to replace mongod with
mongo depending on your install, if I remember correctly)