当我通过pymongo连接时,mongo连接失败了

时间:2013-02-04 08:23:22

标签: python mongodb pymongo

我正在使用它进行插入:

import pymongo
import sys

def main():
    connection = pymongo.Connection("mongodb://localhost", safe=True)

    db = connection.m101
    people = db.people

    person ={'name': 'Barack Obama', 'role':'President',
             'address':{'address1': 'The White House',
                        'street': '1600 Pensylvania Avenue',
                        'state':'DC',
                        'city':'Washington'},
             'interests':['government', 'basketball', 'the middle east']

        }

    people.insert(person)

当我尝试使用写mongo命令时,它会说

Could not connect to server 127.0.0.1:27017 src/mongo
shell mongo.js:91
exception: connection failed

可以做些什么?我正在关注他们的教程!

1 个答案:

答案 0 :(得分:2)

您需要运行mongo守护程序服务器。

$ mongod

您可以在此处查看更多信息: Is mongodb running?