首页 > 代码库 > pymongo
pymongo
import sys
import pymongo
from pymongo import Connection
from pymongo.errors import ConnectionFailure
def main():
try:
conn = Connection(host="localhost", port=27017)
except ConnectionFailure, e:
sys.stderr.write("connection failure: %s" % e)
sys.exit(1)
db = conn["books"]
book_doc = {
"ISDN" : "121",
"Name" : "Art of War"
}
db.books.insert(book_doc, safe=True)
print "insert doc: %s" % book_doc
if __name__ == "__main__":
main()
> db.books.find()
{ "_id" : ObjectId("5466b112a616540bf5a1507b"), "Name" : "Art of War", "ISDN" : "121" }
pymongo
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。