Pymongo operation on MongoDB

Source: Internet
Author: User
Tags string format

#文档地址 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.