Anastasia
Anastasia

Reputation: 874

Can't find where my MongoDB is storing files

I have lost probably one whole day to this problem. I can't find where my MongoDB stores data. it's not in user/data/db. I ran ps -xa | grep mongod and it's not in any of the directories listed there. When I start mongodb and execute show dbs I get a list of empty databases. No idea where on hard drive they are. At this point I have no clue what is happening. The code I am running is taken from another web site and is working. It shows that elements are being inserted into db. I tried everything that I know of and nothing is working. Here is the code:

auth1 = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth1.set_access_token(access_token, access_token_secret)

class StreamListener(tweepy.StreamListener):
    def on_status(self, tweet):
        print tweet.text

    def on_error(self, status_code):
        print 'Error: ' + repr(status_code)
        return False

    def on_data(self, data):
        print 'Ok! Inserting Data.'
        from pymongo import MongoClient
        client = MongoClient()
        client = MongoClient('localhost', 27017)
        db = client.test
        test_id = db.twittertest.insert(json.loads(data))

l = StreamListener()
streamer = tweepy.Stream(auth=auth1, listener=l)
streamer.sample()

Upvotes: 3

Views: 1774

Answers (2)

dstromberg
dstromberg

Reputation: 7187

Depending on what *ix you are using, consider trying lsof -p or fuser.

$ sudo lsof -p $$
[sudo] password for dstromberg:
COMMAND   PID       USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
bash    20786 dstromberg  cwd    DIR    8,6     4096 27525623 /home/dstromberg/src/outside-questions/subprocess
bash    20786 dstromberg  rtd    DIR    8,1     4096        2 /
bash    20786 dstromberg  txt    REG    8,1   975488   130366 /bin/bash
bash    20786 dstromberg  mem    REG    8,1    47616   130322 /lib/x86_64-linux-gnu/libnss_files-2.13.so
bash    20786 dstromberg  mem    REG    8,1    43552   130334 /lib/x86_64-linux-gnu/libnss_nis-2.13.so
bash    20786 dstromberg  mem    REG    8,1    89056   130332 /lib/x86_64-linux-gnu/libnsl-2.13.so
bash    20786 dstromberg  mem    REG    8,1    31584   130324 /lib/x86_64-linux-gnu/libnss_compat-2.13.so
bash    20786 dstromberg  mem    REG    8,1  1595408   130328 /lib/x86_64-linux-gnu/libc-2.13.so
bash    20786 dstromberg  mem    REG    8,1    14768   130321 /lib/x86_64-linux-gnu/libdl-2.13.so
bash    20786 dstromberg  mem    REG    8,1   167952   130362 /lib/x86_64-linux-gnu/libtinfo.so.5.9
bash    20786 dstromberg  mem    REG    8,1   136936   130331 /lib/x86_64-linux-gnu/ld-2.13.so
bash    20786 dstromberg  mem    REG    8,1   256360   103590 /usr/lib/locale/sw_KE/LC_CTYPE
bash    20786 dstromberg  mem    REG    8,1  1170770   103592 /usr/lib/locale/sw_KE/LC_COLLATE
bash    20786 dstromberg  mem    REG    8,1       54   103594 /usr/lib/locale/sw_KE/LC_NUMERIC
bash    20786 dstromberg  mem    REG    8,1     2454   105234 /usr/lib/locale/en_US.utf8/LC_TIME
bash    20786 dstromberg  mem    REG    8,1      286   105233 /usr/lib/locale/en_US.utf8/LC_MONETARY
bash    20786 dstromberg  mem    REG    8,1       57   105231 /usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES
bash    20786 dstromberg  mem    REG    8,1       34   103621 /usr/lib/locale/en_PH.utf8/LC_PAPER
bash    20786 dstromberg  mem    REG    8,1       77   104457 /usr/lib/locale/yi_US.utf8/LC_NAME
bash    20786 dstromberg  mem    REG    8,1      155   105232 /usr/lib/locale/en_US.utf8/LC_ADDRESS
bash    20786 dstromberg  mem    REG    8,1       59   104451 /usr/lib/locale/yi_US.utf8/LC_TELEPHONE
bash    20786 dstromberg  mem    REG    8,1       23   104449 /usr/lib/locale/yi_US.utf8/LC_MEASUREMENT
bash    20786 dstromberg  mem    REG    8,1    26066       73 /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
bash    20786 dstromberg  mem    REG    8,1      373   105235 /usr/lib/locale/en_US.utf8/LC_IDENTIFICATION
bash    20786 dstromberg    0r   CHR    5,0      0t0     1036 /dev/tty
bash    20786 dstromberg    1w   CHR    5,0      0t0     1036 /dev/tty
bash    20786 dstromberg    2w   CHR    5,0      0t0     1036 /dev/tty
bash    20786 dstromberg  255w   CHR    5,0      0t0     1036 /dev/tty

...where "$$" is some pid, EG a pid from your mongo process(es).

Upvotes: 0

Stennie
Stennie

Reputation: 65363

You can find out what the current dbpath is set to by using the getCmdLineOpts command.

For example, using the mongo shell:

db.adminCommand('getCmdLineOpts');

Specifically, you will find the dbpath as:

db.adminCommand('getCmdLineOpts').parsed.dbpath

If there is no dbpath set via the configuration, the default directory is /data/db on Linux/OS X or C:\data\db on Windows.

Upvotes: 3

Related Questions