newliver

newliver的博客

他的个人主页  他的博客

pymongo与mongo shell 之remove

newliver  2010年08月12日 星期四 18:02 | 2526次浏览 | 0条评论

在pymongo中执行dt.remove({'_id':ObjectId("4c63be0f07fe861acf000003")})无法删除此'_id'记录

而在mongo shell中执行>db.uinfo.remove({'_id':ObjectId("4c63be0f07fe861acf000003")})是可以删除

在pymongo中执行dt.remove({'_id':ObjectId("4c63be0f07fe861acf000003")})无法删除此'_id'记录


In [97]: dt.remove({'_id':ObjectId("4c63be0f07fe861acf000003")})
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)

/home/harry/ttt/NewS/HapaUserInfo/<ipython console> in <module>()

NameError: name 'ObjectId' is not defined

 

而在mongo shell中执行>db.uinfo.remove({'_id':ObjectId("4c63be0f07fe861acf000003")})是可以删除的

> show dbs
admin
local
userdb
> use userdb
switched to db userdb
> show collections
system.indexes
uinfo

> db.uinfo.find()


{ "_id" : ObjectId("4c625c9e07fe862352000000"), "pet" : "snake", "car" : "Jeep", "nickname" : "张三张三张", "ukey" : 1234567891 }
{ "_id" : ObjectId("4c63b7ed07fe861acf000002"), "pet" : "snakes", "nickname" : "user115", "ukey" : { "floatApprox" : 287436516743184400, "top" : 66924029, "bottom" : 871628814 } }
{ "_id" : ObjectId("4c63be0f07fe861acf000003"), "pet" : "snakes", "nickname" : "user115", "ukey" : { "floatApprox" : 287436516743184400, "top" : 66924029, "bottom" : 871628814 } }
> db.uinfo.remove({'_id':ObjectId("4c63be0f07fe861acf000003")})


> db.uinfo.find()


{ "_id" : ObjectId("4c625c9e07fe862352000000"), "pet" : "snake", "car" : "Jeep", "nickname" : "张三张三张", "ukey" : 1234567891 }
{ "_id" : ObjectId("4c63b7ed07fe861acf000002"), "pet" : "snakes", "nickname" : "user115", "ukey" : { "floatApprox" : 287436516743184400, "top" : 66924029, "bottom" : 871628814 } }

评论

我的评论:

发表评论

请 登录 后发表评论。还没有在Zeuux哲思注册吗?现在 注册 !

暂时没有评论

Zeuux © 2024

京ICP备05028076号