#文档地址 http://api.mongodb.com/python/current/api/pymongo/collection.html
Collection level of operation:
Find_and _modify (Query={},update=none,upert=false,sort=none,full_response=false,manipulate=false,**kwargs)
Updates and returns an object that is not in favor of using Find_one_and_delete (), Find_one_and_replace (), or find_one_and_update () instead.
C[name] | | C.name gets the subset of collection C name
Full_name gets the full name of the collection, in the form Database_name.collection_name
Name gets the names of the collections
Database Gets the library name of the collection
Create_index (Keys,**kwargs)
Create an index
Keys can be a single field, or a list of 2 element tuples (field names, sort directions). The field name is in string format and the sort direction optional value is (ascending,descending,geo2d,geohaystack,geosphere,hashed, TEXT)
Example: My_collection.create_index ([' Mike ', Pymongo. Descending), (' Eliot ', Pymongo. Ascending)],backgroud=true)
Parameters in **kwargs can be passed in as a keyword parameter, including but not limited to the following parameters:
Name of the index, not supplied, is automatically named in order
The expireafterseconds int type is used to create a collection that has an expiration date. MongoDB will automatically delete the records in this collection after the set number of seconds. The field for this index must be a UTC datetime or data that will not expire.
Create_indexes (indexes)
Create multiple indexes
Example: from Pymongo import indexmodel,ascending,descending
Index1=indexmodel ([' Hello ', descending), (' World ', ascending)],name= ' Hello_world ')
Index2=indexmodel ([(' Goodbye ', descending)])
My_collection.create_indexes ([Index1,index2])
Pymongo operation on MongoDB