码迷,mamicode.com
首页 > 其他好文 > 详细

pymongo

时间:2014-11-15 11:34:47      阅读:171      评论:0      收藏:0      [点我收藏+]

标签: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

标签:pymongo

原文地址:http://jasonyu37.blog.51cto.com/8877469/1576728

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!