开发者

How come I can't insert into Mongo? It used to work

con = pymongo.Connection(MONGO_DOC_HOST, MONGO_DOC_PORT)
db = con.testdb
datasets = db.datasets

for post in db.datasets.find({"test_set":"xyz"}).sort("num_favs",pymongo.DESCENDING).limit(2):
    print post #this works, and it prints fine!

post = {"hi":"abc"}
mongo_id = datasets.insert(post)

When I do datasets.insert, and print out the mongo_id. The id prints!

However, when I do: db.datasets.find()开发者_如何学JAVA.count() in the mongo console, the count is still the same...

Weird. When I do this in console..I get this error:

> db.datasets.insert({"gooder":"absdlk"})
E11000 duplicate key error index: fabletest.datasets.$flickr_original_1  dup key: { : null }

That's weird, I didn't index "gooder" at all.


are you definitely hitting the same database ("testdb") in both cases? the default db in the shell is "test"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜