日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pymongo 使用测试

發布時間:2024/4/15 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pymongo 使用测试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
>>> import pymongo >>> uri = "mongodb://recall:123456@oceanic.mongohq.com:10062/must" >>> client = pymongo.MongoClient(uri) #連接到數據庫 >>> db = client.must #選擇數據庫名 >>> db.collection_names #查看所有聚集名,相當與show_tables <bound method Database.collection_names of Database(MongoClient('oceanic.mongohq.com', 10062), u'must')> >>> table = db.mytable #創建聚集 >>> count = table.count() #查看聚集中的數目 >>> count 0 >>> monster = {"name":"Dracule","occupation":"Blood Suker","tags":["vampire","teeth","bat"],"data":"19981010"} >>> insert_id = table.insert(monster) #插入數據 >>> for monster_one in table.find(): ... print monster_one ... ... {u'occupation': u'Blood Suker', u'_id': ObjectId('53510fcad6ca3fb153c5681d'), u'data': u'19981010', u'name': u'Dracule', u'tags': [u'vampire', u'teeth', u'bat']} >>> print table.find_one({"name":"Dracule"}) {u'occupation': u'Blood Suker', u'_id': ObjectId('53510fcad6ca3fb153c5681d'), u'data': u'19981010', u'name': u'Dracule', u'tags': [u'vampire', u'teeth', u'bat']}

可查看?http://docs.mongohq.com/languages/python.html

import os import datetime import pymongo from pymongo import MongoClient# Grab our connection information from the MONGOHQ_URL environment variable # (mongodb://linus.mongohq.com:10045 -u username -pmy_password) MONGO_URL = os.environ.get('MONGOHQ_URL') #connection = Connection(MONGO_URL) client = MongoClient(MONGO_URL)# Specify the database db = client.mytestdatabase # Print a list of collections print db.collection_names()# Specify the collection, in this case 'monsters' collection = db.monsters# Get a count of the documents in this collection count = collection.count() print "The number of documents you have in this collection is:", count# Create a document for a monster monster = {"name": "Dracula","occupation": "Blood Sucker","tags": ["vampire", "teeth", "bat"],"date": datetime.datetime.utcnow()}# Insert the monster document into the monsters collection monster_id = collection.insert(monster)# Print out our monster documents for monster in collection.find():print monster# Query for a particular monster print collection.find_one({"name": "Dracula"})

?

?

轉載于:https://www.cnblogs.com/tk091/p/3673984.html

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的pymongo 使用测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。