我遵循MongoDB教程测试如何将数据插入现有数据库。你知道吗
这是我在Python文件中的代码:
from pymongo import MongoClient
from datetime import datetime
client = MongoClient()
db = client.test
result = db.restaurants.insert_one(
{
"address": {
"street": "2 Avenue",
"zipcode": "10075",
"building": "1480",
"coord": [-73.9557413, 40.7720266]
},
"borough": "Manhattan",
"cuisine": "Italian",
"grades": [
{
"date": datetime.strptime("2014-10-01", "%Y-%m-%d"),
"grade": "A",
"score": 11
},
{
"date": datetime.strptime("2014-01-16", "%Y-%m-%d"),
"grade": "B",
"score": 17
}
],
"name": "Vella",
"restaurant_id": "41704620"
}
)
我在终端上运行python3 (filename)
。
我得到的结果是:
2015-11-22T14:08:55.779-0800 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53193 #41 (2 connections now open)
2015-11-22T14:09:10.243-0800 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53195 #42 (3 connections now open)
2015-11-22T14:09:10.750-0800 I NETWORK [conn42] end connection 127.0.0.1:53195 (2 connections now open)
两个连接来自一个名为robomongo的程序,该程序允许查看MongoDB中的数据库。我看到那个连接是开的和关的。但是当我检查robomongo的数据时,我找不到额外的数据。
我仔细检查了数据库的名称是test
,集合的名称是restaurants
。
我导入原始数据集的方式如下:
mongoimport --db test --collection restaurants --drop --file primer-dataset.json
我做错什么了?你知道吗
你的代码绝对有效。确保连接到正确的主机和端口。脚本假定使用默认设置localhost和端口27017。你知道吗
相关问题 更多 >
编程相关推荐