Download Pymongo-2.6.3.win-amd64-py2.7.exe on the Python website
Installing Pymongo-2.6.3.win-amd64-py2.7.exe
Test with the official use case
Open a command prompt and enter the Python runtime environment.
Import Pymongo Module
>>> Import Pymongo
Establish a link to the local MongoDB service
>>> client = Pymongo. Mongoclient ("localhost", 27017)
Connect the test Database
>>> db = Client.test
Query the database name of the connection
>>> Db.nameu ' Test '
Querying My_collection Collection Information
>>> db.my_collectioncollection (Database (mongoclient (' localhost ', 27017), U ' Test '), U ' my_collection ')
Add some test documents/objects to the My_collection collection
>>> Db.my_collection.save ({"X": Ten}) ObjectId (' 530034752052d502c4a250aa ') >>> Db.my_ Collection.save ({"X": 8}) ObjectId (' 5300347d2052d502c4a250ab ') >>> db.my_collection.save ({"X": 11}) ObjectId (' 530034832052d502c4a250ac ')
Querying a document/object in the My_collection collection
>>> Db.my_collection.find_one () {u ' x ': Ten, U ' _id ': ObjectId (' 530034752052D502C4A250AA ')}
Queries all documents/objects in the My_collection collection and iterates through the output
Indentationerror:expected an indented block>>> for item in Db.my_collection.find (): ... print item["x"] ... 10811
Create an index for the My_collection collection
>>> Db.my_collection.create_index ("x") u ' x_1 '
Queries all documents/objects in the My_collection collection and traverses the output in ascending order
>>> for item in Db.my_collection.find (). Sort ("X", Pymongo. Ascending): ... print item["x"] ... 81011
Queries all documents/objects in the My_collection collection, and certain rules traverse the output
>>> [item["x"] for item in Db.my_collection.find (). Limit (2). Skip (1)][8, 11]
Add MongoDB support for Python under Windows platform Pymongo