找不到我的MongoDB存储文件的位置

2024-09-29 03:31:51 发布

您现在位置:Python中文网/ 问答频道 /正文

这个问题我大概花了一整天的时间。我找不到我的MongoDB存储数据的位置。它不在user/data/db中。我运行了ps-xa | grep mongod,它不在列出的任何目录中。当我启动mongodb并执行show dbs时,我得到一个空数据库的列表。不知道硬盘在哪里。在这一点上,我不知道发生了什么。我正在运行的代码来自另一个网站,并且正在运行。它显示元素被插入到数据库中。我尝试了我所知道的一切,但没有任何效果。代码如下:

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()

Tags: selfclienttoken数据库dbdataaccesson
2条回答

根据您使用的*ix,考虑尝试lsof-p或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

…其中“$$”是一些pid,例如来自mongo进程的pid。在

您可以通过使用^{} command找到当前dbpath的设置。在

例如,使用mongoshell:

db.adminCommand('getCmdLineOpts');

具体来说,您将发现dbpath为:

^{pr2}$

如果没有通过配置设置dbpath,那么默认目录是/data/db(在Linux/OS X上)或{}(在Windows上)。在

相关问题 更多 >