简体   繁体   English

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

[英]mongo connection failed when I have made connection through pymongo

I am using this for insertion:我正在使用它进行插入:

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)

And when I try to use writing mongo command it says当我尝试使用编写mongo命令时,它说

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

What can be done?可以做什么? I am following their tutorial!我正在关注他们的教程!

You need to run mongo daemon server.您需要运行 mongo 守护进程服务器。

$ mongod $ mongod

You can look more information here: Is mongodb running?您可以在此处查看更多信息: 是否正在运行 mongodb?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM