@@ -51,37 +51,39 @@ Examples
51
51
========
52
52
Here's a basic example (for more see the *examples * section of the docs):
53
53
54
- >>> import pymongo
55
- >>> client = pymongo.MongoClient(" localhost" , 27017 )
56
- >>> db = client.test
57
- >>> db.name
58
- u'test'
59
- >>> db.my_collection
60
- Collection(Database(MongoClient('localhost', 27017), u'test'), u'my_collection')
61
- >>> db.my_collection.save({" x" : 10 })
62
- ObjectId('4aba15ebe23f6b53b0000000')
63
- >>> db.my_collection.save({" x" : 8 })
64
- ObjectId('4aba160ee23f6b543e000000')
65
- >>> db.my_collection.save({" x" : 11 })
66
- ObjectId('4aba160ee23f6b543e000002')
67
- >>> db.my_collection.find_one()
68
- {u'x': 10, u'_id': ObjectId('4aba15ebe23f6b53b0000000')}
69
- >>> for item in db.my_collection.find():
70
- ... print item[" x" ]
71
- ...
72
- 10
73
- 8
74
- 11
75
- >>> db.my_collection.create_index(" x" )
76
- u'x_1'
77
- >>> for item in db.my_collection.find().sort(" x" , pymongo.ASCENDING ):
78
- ... print item[" x" ]
79
- ...
80
- 8
81
- 10
82
- 11
83
- >>> [item[" x" ] for item in db.my_collection.find().limit(2 ).skip(1 )]
84
- [8, 11]
54
+ .. code-block :: pycon
55
+
56
+ >>> import pymongo
57
+ >>> client = pymongo.MongoClient("localhost", 27017)
58
+ >>> db = client.test
59
+ >>> db.name
60
+ u'test'
61
+ >>> db.my_collection
62
+ Collection(Database(MongoClient('localhost', 27017), u'test'), u'my_collection')
63
+ >>> db.my_collection.save({"x": 10})
64
+ ObjectId('4aba15ebe23f6b53b0000000')
65
+ >>> db.my_collection.save({"x": 8})
66
+ ObjectId('4aba160ee23f6b543e000000')
67
+ >>> db.my_collection.save({"x": 11})
68
+ ObjectId('4aba160ee23f6b543e000002')
69
+ >>> db.my_collection.find_one()
70
+ {u'x': 10, u'_id': ObjectId('4aba15ebe23f6b53b0000000')}
71
+ >>> for item in db.my_collection.find():
72
+ ... print item["x"]
73
+ ...
74
+ 10
75
+ 8
76
+ 11
77
+ >>> db.my_collection.create_index("x")
78
+ u'x_1'
79
+ >>> for item in db.my_collection.find().sort("x", pymongo.ASCENDING):
80
+ ... print item["x"]
81
+ ...
82
+ 8
83
+ 10
84
+ 11
85
+ >>> [item["x"] for item in db.my_collection.find().limit(2).skip(1)]
86
+ [8, 11]
85
87
86
88
Documentation
87
89
=============
0 commit comments