SequoiaDB
 All Classes Functions
Public Member Functions | List of all members
pysequoiadb.collection.collection Class Reference
Inheritance diagram for pysequoiadb.collection.collection:

Public Member Functions

def __init__
 
def __del__
 
def __repr__
 
def get_count
 
def split_by_condition
 
def split_by_percent
 
def split_async_by_condition
 
def split_async_by_percent
 
def bulk_insert
 
def insert
 
def insert_with_flag
 
def update
 
def upsert
 
def save
 
def delete
 
def query
 
def query_and_update
 
def query_and_remove
 
def create_index
 
def create_index_with_option
 
def get_indexes
 
def get_index_info
 
def is_index_exist
 
def drop_index
 
def get_index_stat
 
def get_collection_name
 
def get_cs_name
 
def get_full_name
 
def aggregate
 
def get_query_meta
 
def attach_collection
 
def detach_collection
 
def create_lob
 
def create_lob_id
 
def open_lob
 
def get_lob
 
def remove_lob
 
def truncate_lob
 
def list_lobs
 
def query_one
 
def explain
 
def truncate
 
def alter
 
def create_id_index
 
def drop_id_index
 
def enable_sharding
 
def disable_sharding
 
def enable_compression
 
def disable_compression
 
def set_attributes
 
def create_autoincrement
 
def drop_autoincrement
 

Detailed Description

Collection for SequoiaDB

All operation need deal with the error code returned first, if it has.
Every error code is not SDB_OK(or 0), it means something error has appeared,
and user should deal with it according the meaning of error code printed.

@version: execute to get version
          >>> import pysequoiadb
          >>> print pysequoiadb.get_version()

@notice : The dict of built-in Python is hashed and non-ordered. so the
          element in dict may not the order we make it. we make a dict and
          print it like this:
          ...
          >>> a = {"avg_age":24, "major":"computer science"}
          >>> a
          >>> {'major': 'computer science', 'avg_age': 24}
          ...
          the elements order it is not we make it!!
          therefore, we use bson.SON to make the order-sensitive dict if the
          order is important such as operations in "$sort", "$group",
          "split_by_condition", "aggregate","create_collection"...
          In every scene which the order is important, please make it using
          bson.SON and list. It is a subclass of built-in dict
          and order-sensitive

Constructor & Destructor Documentation

def pysequoiadb.collection.collection.__init__ (   self)
create a new collection.

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.__del__ (   self)
delete a object existed.

Exceptions:
   pysequoiadb.error.SDBBaseError

Member Function Documentation

def pysequoiadb.collection.collection.aggregate (   self,
  aggregate_options 
)
Execute aggregate operation in specified collection.

Parameters:
   Name               Type       Info:
   aggregate_options  list/tuple The array of dict objects.
                               bson.SON may need if the element is
                               order-sensitive.
                               eg.
                               {'$sort':bson.SON([("name",-1), ("age":1)])}
                               it will be ordered descending by 'name'
                               first, and be ordered ascending by 'age'
Return values:
   a cursor object of result
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.alter (   self,
  options 
)
Alter the collection.
Parameters:
   Name         Type     Info:
   options      dict     The options are as following:
                 ReplSize            : Assign how many replica nodes need to be synchronized when a write
                                     request (insert, update, etc) is executed, default is 1
                 ShardingKey         : Assign the sharding key, foramt: { ShardingKey: { <key name>: <1/-1>} },
                                     1 indicates positive order, -1 indicates reverse order.
                                     e.g. { ShardingKey: { age: 1 } }
                 ShardingType        : Assign the sharding type, default is "hash"
                 Partition           : The number of partition, it is valid when ShardingType is "hash",
                                     the range is [2^3,2^20], default is 4096
                 AutoSplit           : Whether to enable the automatic partitioning, it is valid when
                                     ShardingType is "hash", defalut is false
                 EnsureShardingIndex : Whether to build sharding index, default is true
                 Compressed          : Whether to enable data compression, default is true
                 CompressionType     : The compression type of data, could be "snappy" or "lzw", default is "lzw"
                 StrictDataMode      : Whether to enable strict date mode in numeric operations, default is false
                 AutoIncrement       : Assign attributes of an autoincrement field or batch autoincrement fields
                                     e.g. { AutoIncrement : { Field : "a", MaxValue : 2000 } },
                                     { AutoIncrement : [ { Field : "a", MaxValue : 2000}, { Field : "a", MaxValue : 4000 } ] }
                 AutoIndexId         : Whether to build "$id" index, default is true
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.attach_collection (   self,
  cl_full_name,
  options 
)
Attach the specified collection.

Parameters:
   Name            Type  Info:
   subcl_full_name str   The name of the subcollection.
   options         dict  The low boudary and up boudary
                       eg: {"LowBound":{a:1},"UpBound":{a:100}}
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.bulk_insert (   self,
  flag,
  records 
)
Insert a bulk of record into current collection.

Parameters:
   Name        Type       Info:
   flag        int        See Info as below.
   records     list/tuple The list of inserted records.
Return values:
    A dict object contains the insert details. As follow:
    - InsertedNum    : The number of records successfully inserted, including replaced and ignored records.
    - DuplicatedNum  : The number of records ignored or replaced due to duplicate key conflicts.
    - LastGenerateID : The max value of all auto-increments that the first record inserted contains. The
               result will include this field if current collection has auto-increments.
    - _id            : ObjectId of the inserted record. The result will include field "_id" if
               FLG_INSERT_RETURN_OID is used.
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   The flag to control the behavior of inserting. The value of flag default to be INSERT_FLG_DEFAULT, and it
   can choose the follow values:
     INSERT_FLG_DEFAULT      : While INSERT_FLG_DEFAULT is set, database will stop inserting when the record
                       hit index key duplicate error.
     INSERT_FLG_CONTONDUP    : If the record hit index key duplicate error, database will skip it.
     INSERT_FLG_RETURN_OID   : Return the value of "_id" field in the record.
     INSERT_FLG_REPLACEONDUP : If the record hit index key duplicate error, database will replace the existing
                       record by the inserting new record and then go on inserting.
     INSERT_FLG_CONTONDUP_ID :  The flag represent the error of the dup key will be ignored when the dup key is '_id'.
     INSERT_FLG_REPLACEONDUP_ID : The flag represents the error of the dup key will be ignored when the dup key is '_id',
                          and the original record will be replaced by new record.
def pysequoiadb.collection.collection.create_autoincrement (   self,
  options 
)
Create autoincrement field on collection.

Parameters:
   Name      Type           Info:
   options   dict           The options for create_autoincrement. e.g. { Field: "a", MaxValue:2000 }.
   options   list/tuple     It can also be a list/tuple of such dict. e.g. [ { Field: "a", MaxValue:2000 }, { Field: "b", MaxValue:5000 } ]
                    Available options are as below:
                    Field          : The name of autoincrement field
                    StartValue     : The start value of autoincrement field
                    MinValue       : The minimum value of autoincrement field
                    MaxValue       : The maxmun value of autoincrement field
                    Increment      : The increment value of autoincrement field
                    CacheSize      : The cache size of autoincrement field
                    AcquireSize    : The acquire size of autoincrement field
                    Cycled         : The cycled flag of autoincrement field
                    Generated      : The generated mode of autoincrement field
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.create_id_index (   self,
  options = None 
)
Create the id index.

Parameters:
   Name         Type     Info:
   options      dict     The configuration options for id index.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.create_index (   self,
  index_def,
  idx_name,
  is_unique = False,
  is_enforced = False,
  buffer_size = 64 
)
Create an index in current collection.
Parameters:
   Name         Type  Info:
   index_def    dict  The dict object of index element.
                      eg. {'name':1, 'age':-1}
   idx_name     str   The index name.
   is_unique    bool  Whether the index elements are unique or not.
   is_enforced  bool  Whether the index is enforced unique, this element
                      is meaningful when isUnique is set to true.
   buffer_size  int   The size of sort buffer used when creating index,
                      the unit is MB, zero means don't use sort buffer
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.create_index_with_option (   self,
  index_def,
  idx_name,
  option = None 
)
Create an index in current collection.

Parameters:
   Name         Type     Info:
   index_def    dict     The dict object of index element.
                         eg. {'name':1, 'age':-1}
   idx_name     str      The index name.
   option      dict      The configuration option for index. visit this url:
                         "http://doc.sequoiadb.com/cn/sequoiadb-cat_id-1432190830-edition_id-304"
                         to get more details.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.create_lob (   self,
  oid = None 
)
Create a lob.

Parameters:
   Name     Type           Info:
   oid      bson.ObjectId  Specified the oid of lob to be created,
                           if None, the oid is generated automatically
Return values:
   A lob object.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.create_lob_id (   self,
  timestamp = None 
)
Create a lob id.

Parameters:
   Name        Type         Info:
   timestamp   str          Used to generate lob id, if be None the timestamp will be generated by server.
                            format:YYYY-MM-DD-HH.mm.ss. eg: "2019-07-23-18.04.07".
Return values:
   An ObjectId object of lob.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.delete (   self,
  kwargs 
)
Delete the matching documents in current collection.

Parameters:
   Name        Type  Info:
   **kwargs          Useful options are below
   - condition dict  The matching rule, match all the documents
                     if not provided.
   - hint      dict  The hint, automatically match the optimal hint
                     if not provided.
   - flags     int   See Info as below.
Return values:
    A dict object contains the deletion details. As follow:
    - DeletedNum : The number of records successfully deleted.
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   The delete flags, default to be 0, it can choose the follow values:
     DELETE_FLG_DELETE_ONE : The flag represent whether to delete only one matched record
                             or all matched records.
def pysequoiadb.collection.collection.detach_collection (   self,
  sub_cl_full_name 
)
Dettach the specified collection.

Parameters:
   Name            Type  Info:
   subcl_full_name str   The name fo the subcollection.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.disable_compression (   self)
Alter the collection to disable compression.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.disable_sharding (   self)
Alter the collection to disable sharding.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.drop_autoincrement (   self,
  names 
)
Drop autoincrement field on collection.

Parameters:
   Name      Type           Info:
   names     str            The name(s) of autoincrement field. e.g. "a"
   names     list/tuple     It can also be a list/tuple of such str. e.g. [ "a", "b" ]
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.drop_id_index (   self)
Drop the id index.

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.drop_index (   self,
  idx_name 
)
Removed the named index of current collection.

Parameters:
   Name         Type  Info:
   idx_name     str   The index name.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.enable_compression (   self,
  options 
)
Alter the collection to enable compression.
Parameters:
   Name         Type     Info:
   options      dict     The options to alter
                 CompressionType : The compression type of data, could be "snappy" or "lzw"
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.enable_sharding (   self,
  options 
)
Alter the collection to enable sharding.
Parameters:
   Name         Type     Info:
   options      dict     The options to alter
                 ShardingKey  : Assign the sharding key
                 ShardingType : Assign the sharding type
                 Partition    : When the ShardingType is "hash", need to assign Partition, it's the bucket number for hash, the range is [2^3,2^20]
                 EnsureShardingIndex : Assign to true to build sharding index
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.explain (   self,
  kwargs 
)
Get the matching documents in current collection.

Parameters:
   Name              Type     Info:
   **kwargs                   Useful options are below
   - condition       dict     The matching rule, update all the
                            documents if not provided.
   - selected        dict     The selective rule, return the whole
                            document if not provided.
   - order_by        dict     The ordered rule, result set is unordered
                            if not provided.
   - hint            dict     The hint, automatically match the optimal
                            hint if not provided.
   - num_to_skip     long     Skip the first numToSkip documents,
                            default is 0L.
   - num_to_return   long     Only return numToReturn documents,
                            default is -1L for returning
                            all results.
   - flags           int      The query flags, default to be 0. Please see
                            the definition of follow flags for
                            more detail. See Info as below.
   - options         dict
Return values:
   a cursor object of query
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   query flags:
   QUERY_FLG_FORCE_HINT      : Force to use specified hint to query, if database has no index assigned by the hint, fail to query
   QUERY_FLG_PARALLED        : Enable parallel sub-query, each sub-query will finish scanning different part of data
   QUERY_FLG_WITH_RETURNDATA : In general, query won't return data until cursor gets the record from database, when adding this flag, return data in query response, it will be more high-performance
def pysequoiadb.collection.collection.get_collection_name (   self)
Get the name of current collection.

Return values:
   The name of current collection
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.get_count (   self,
  condition = None 
)
Get the count of matching documents in current collection.

Parameters:
   Name         Type     Info:
   condition    dict     The matching rule, return the count of all
                       documents if None.
Return values:
   count of result
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.get_cs_name (   self)
Get the name of current collection space.

Return values:
   The name of current collection space
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.get_full_name (   self)
Get the full name of specified collection in current collection space.

Return values:
   The full name of current collection
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.get_index_info (   self,
  idx_name 
)
Get the information of specified index in current collection.

Parameters:
   Name         Type  Info:
   idx_name     str   The index name.
Return values:
   a record of json/dict
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.get_index_stat (   self,
  idx_name,
  detail = False 
)
Get the statistics of the index.

Parameters:
   Name         Type  Info:
   idx_name     str   The index name.
   detail       bool  Whether show the detail information.
Return values:
   a dict object of result
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.get_indexes (   self,
  idx_name = None 
)
Get all of or one of the indexes in current collection.

Parameters:
   Name         Type  Info:
   idx_name     str   The index name, returns all of the indexes if this parameter is None.
              Deprecated, use get_index_info to get specific index.
Return values:
   a cursor object of result
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.get_lob (   self,
  oid 
)
get the specified lob.

Parameters:
   Name     Type                 Info:
   oid      str/bson.ObjectId    The specified oid
Return values:
   a lob object
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.get_query_meta (   self,
  kwargs 
)
Get the index blocks' or data blocks' infomations for concurrent query.

Parameters:
   Name              Type     Info:
   **kwargs                   Useful options are below
   - condition       dict     The matching rule, return the whole range
                            of index blocks if not provided.
                            eg:{"age":{"$gt":25},"age":{"$lt":75}}.
   - order_by        dict     The ordered rule, result set is unordered
                            if not provided.bson.SON may need if it is
                            order-sensitive.
   - hint            dict     One of the indexs in current collection,
                            using default index to query if not
                            provided.
                            eg:{"":"ageIndex"}.
   - num_to_skip     long     Skip the first num_to_skip documents,
                            default is 0L.
   - num_to_return   long     Only return num_to_return documents,
                            default is -1L for returning all results.
Return values:
   a cursor object of query
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.insert (   self,
  record 
)
Insert a record into current collection.

Parameters:
   Name      Type    Info:
   record    dict    The inserted record.
Return values:
   An ObjectId object of record inserted. eg: { '_id': ObjectId('5d5149ade3071dce3692e93b') }
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.insert_with_flag (   self,
  record,
  flag = INSERT_FLG_DEFAULT 
)
Insert a record into current collection.

 Parameters:
    Name      Type    Info:
    record    dict    The inserted record.
    flag      int     See Info as below.
 Return values:
    A dict object contains the insert details. As follow:
    - InsertedNum    : The number of records successfully inserted, including replaced and ignored records.
    - DuplicatedNum  : The number of records ignored or replaced due to duplicate key conflicts.
    - LastGenerateID : The max value of all auto-increments that the inserted record contains. The result
               will include this field if current collection has auto-increments.
    - _id            : ObjectId of the inserted record. The result will include field "_id" if
               FLG_INSERT_RETURN_OID is used.
 Exceptions:
    pysequoiadb.error.SDBBaseError
 Info:
   The flag to control the behavior of inserting. The value of flag default to be INSERT_FLG_DEFAULT, and it
   can choose the follow values:
     INSERT_FLG_DEFAULT      : While INSERT_FLG_DEFAULT is set, database will stop inserting when the record
                       hit index key duplicate error.
     INSERT_FLG_CONTONDUP    : If the record hit index key duplicate error, database will skip it.
     INSERT_FLG_RETURN_OID   : Return the value of "_id" field in the record.
     INSERT_FLG_REPLACEONDUP : If the record hit index key duplicate error, database will replace the existing
                       record by the inserting new record and then go on inserting.
     INSERT_FLG_CONTONDUP_ID :  The flag represent the error of the dup key will be ignored when the dup key is '_id'.
     INSERT_FLG_REPLACEONDUP_ID : The flag represents the error of the dup key will be ignored when the dup key is '_id',
                          and the original record will be replaced by new record.
def pysequoiadb.collection.collection.is_index_exist (   self,
  idx_name 
)
Test if the specified index exists or not.

Parameters:
   Name         Type  Info:
   idx_name     str   The index name.
Return values:
   bool
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.list_lobs (   self,
  kwargs 
)
list lobs.

Parameters:
   Name              Type     Info:
   - condition       dict     The matching rule, return all the lob if not provided.
   - selected        dict     The selective rule, return the whole infomation if not provided.
   - order_by        dict     The ordered rule, result set is unordered if not provided.
   - hint            dict     Specified options. eg. {"ListPieces": 1} means get the detail piece info of lobs.
   - num_to_skip     long     Skip the first numToSkip lob, default is 0.
   - num_to_Return   long     Only return numToReturn lob, default is -1 for returning all results.

Return values:
   a cursor object of query
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.open_lob (   self,
  oid,
  mode = LOB_READ 
)
open the specified lob to read or write.

Parameters:
   Name     Type                 Info:
   oid      str/bson.ObjectId    The specified oid
   mode     int                  The open mode:
                         lob.LOB_READ for reading.
                         lob.LOB_WRITE for writing.
                         lob.LOB_SHARE_READ for share reading.
                         lob.LOB_SHARE_READ | lob.LOB_WRITE for both reading and writing.
Return values:
   a lob object
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.query (   self,
  kwargs 
)
Get the matching documents in current collection.

Parameters:
   Name              Type     Info:
   **kwargs                   Useful options are below
   - condition       dict     The matching rule, update all the
                            documents if not provided.
   - selector        dict     The selective rule, return the whole
                            document if not provided.
   - order_by        dict     The ordered rule, result set is unordered
                            if not provided.
   - hint            dict     The hint, automatically match the optimal
                            hint if not provided.
   - num_to_skip     long     Skip the first numToSkip documents,
                            default is 0L.
   - num_to_return   long     Only return numToReturn documents,
                            default is -1L for returning
                            all results.
   - flags           int      The query flags, default to be 0. Please see
                            the definition of follow flags for
                            more detail. See Info as below.
Return values:
   a cursor object of query
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   query flags:
   QUERY_FLG_FORCE_HINT      : Force to use specified hint to query, if database has no index assigned by the hint, fail to query
   QUERY_FLG_PARALLED        : Enable parallel sub-query, each sub-query will finish scanning different part of data
   QUERY_FLG_WITH_RETURNDATA : In general, query won't return data until cursor gets the record from database, when adding this flag, return data in query response, it will be more high-performance
   QUERY_PREPARE_MORE        : Enable prepare more data when querying
   QUERY_FLG_FOR_UPDATE      : When the transaction is turned on and the transaction isolation level is "RC", the transaction lock will be released after the record is read by default.
                       However, when setting this flag, the transaction lock will not be released until the transaction is committed or rollbacked. When the transaction is turned off or
                       the transaction isolation level is "RU", the flag does not work
def pysequoiadb.collection.collection.query_and_remove (   self,
  kwargs 
)
Get the matching documents in current collection and remove.

Parameters:
   Name            Type     Info:
   **kwargs                 Useful options are below
   - condition     dict     The matching rule, update all the
                            documents if not provided.
   - selector      dict     The selective rule, return the whole
                            document if not provided.
   - order_by      dict     The ordered rule, result set is unordered
                            if not provided.
   - hint          dict     The hint, automatically match the optimal
                            hint if not provided.
   - num_to_skip   long     Skip the first numToSkip documents,
                            default is 0L.
   - num_to_return long     Only return numToReturn documents,
                            default is -1L for returning
                            all results.
   - flags         int      The query flags, default to be 0. Please see
                            the definition of follow flags for
                            more detail. See Info as below.
Return values:
   a cursor object of query
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   query flags:
   QUERY_FLG_FORCE_HINT      : Force to use specified hint to query, if database has no index assigned by the hint, fail to query
   QUERY_FLG_PARALLED        : Enable parallel sub-query, each sub-query will finish scanning different part of data
   QUERY_FLG_WITH_RETURNDATA : In general, query won't return data until cursor gets the record from database, when adding this flag, return data in query response, it will be more high-performance
   QUERY_FLG_FOR_UPDATE      : When the transaction is turned on and the transaction isolation level is "RC", the transaction lock will be released after the record is read by default.
                       However, when setting this flag, the transaction lock will not be released until the transaction is committed or rollbacked. When the transaction is turned off or
                       the transaction isolation level is "RU", the flag does not work.
def pysequoiadb.collection.collection.query_and_update (   self,
  update,
  kwargs 
)
Get the matching documents in current collection and update.

Parameters:
   Name            Type     Info:
   update          dict     The update rule, can't be None.
   **kwargs                 Useful options are below
   - condition     dict     The matching rule, update all the
                            documents if not provided.
   - selector      dict     The selective rule, return the whole
                            document if not provided.
   - order_by      dict     The ordered rule, result set is unordered
                            if not provided.
   - hint          dict     The hint, automatically match the optimal
                            hint if not provided.
   - num_to_skip   long     Skip the first numToSkip documents,
                            default is 0L.
   - num_to_return long     Only return numToReturn documents,
                            default is -1L for returning
                            all results.
   - flags         int      The query flags, default to be 0. Please see
                            the definition of follow flags for
                            more detail. See Info as below.
   - return_new    bool     When True, returns the updated document rather than the original

Return values:
   a cursor object of query
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   query flags:
   QUERY_FLG_FORCE_HINT                 : Force to use specified hint to query, if database have
                                        no index assigned by the hint, failed to query
   QUERY_FLG_PARALLED                   : Enable parallel sub-query, each sub-query will finish scanning
                                        different part of data
   QUERY_FLG_WITH_RETURNDATA            : In general, query won't return data until cursor gets from
                                        database, when adding this flag, return data in query response,
                                        it will be more high-performance
   QUERY_FLG_KEEP_SHARDINGKEY_IN_UPDATE : The sharding key in update rule is not filtered, when executing
                                        queryAndUpdate.
   QUERY_FLG_FOR_UPDATE                 : When the transaction is turned on and the transaction isolation level is "RC", the transaction lock will be released after the record is read by default.
                                  However, when setting this flag, the transaction lock will not be released until the transaction is committed or rollbacked. When the transaction is turned off or
                                  the transaction isolation level is "RU", the flag does not work.
def pysequoiadb.collection.collection.query_one (   self,
  kwargs 
)
Get one matching documents in current collection.

Parameters:
   Name              Type     Info:
   **kwargs                   Useful options are below
   - condition       dict     The matching rule, update all the
                            documents if not provided.
   - selected        dict     The selective rule, return the whole
                            document if not provided.
   - order_by        dict     The ordered rule, result set is unordered
                            if not provided.
   - hint            dict     The hint, automatically match the optimal
                            hint if not provided.
   - num_to_skip     long     Skip the first numToSkip documents,
                            default is 0L.
   - flags           int      The query flags, default to be 0. Please see
                            the definition of follow flags for
                            more detail. See Info as below.
Return values:
   a record of json/dict
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   query flags:
   QUERY_FLG_FORCE_HINT      : Force to use specified hint to query, if database has no index assigned by the hint, fail to query
   QUERY_FLG_PARALLED        : Enable parallel sub-query, each sub-query will finish scanning different part of data
   QUERY_FLG_WITH_RETURNDATA : In general, query won't return data until cursor gets the record from database, when adding this flag, return data in query response, it will be more high-performance
   QUERY_PREPARE_MORE        : Enable prepare more data when querying
   QUERY_FLG_FOR_UPDATE      : When the transaction is turned on and the transaction isolation level is "RC", the transaction lock will be released after the record is read by default.
                       However, when setting this flag, the transaction lock will not be released until the transaction is committed or rollbacked. When the transaction is turned off or
                       the transaction isolation level is "RU", the flag does not work
def pysequoiadb.collection.collection.remove_lob (   self,
  oid 
)
remove lob.

Parameters:
   Name     Type                 Info:
   oid      str/bson.ObjectId    The oid of the lob to be remove.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.save (   self,
  doc 
)
Upsert the record using the main key '_id' of the record.

Parameters:
   Name          Type  Info:
   doc           dict  The updating rule.
Exceptions:
   pysequoiadb.error.SDBBaseError
Note:
   It won't work to update the "ShardingKey" field, but the other fields
 take effect.
Deprecated:
   This function is deprecated, use upsert() or insert_with_flag() instead of it.
def pysequoiadb.collection.collection.set_attributes (   self,
  options 
)
Alter the collection.
Parameters:
   Name         Type     Info:
   options      dict     The options to alter
                 ReplSize     : Assign how many replica nodes need to be synchronized when a write request(insert, update, etc) is executed
                 ShardingKey  : Assign the sharding key
                 ShardingType : Assign the sharding type
                 Partition    : When the ShardingType is "hash", need to assign Partition, it's the bucket number for hash, the range is [2^3,2^20]
                 CompressionType : The compression type of data, could be "snappy" or "lzw"
                 EnsureShardingIndex : Assign to true to build sharding index
                 StrictDataMode : Using strict date mode in numeric operations or not
                 AutoIncrement : Assign attributes of an autoincrement field or batch autoincrement fields. e.g { "AutoIncrement": { "Field": "studentID", "StartValue": 1 } }
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.split_async_by_condition (   self,
  source_group_name,
  target_group_name,
  split_condition,
  split_end_condition = None 
)
Split the specified collection from source replica group to target
   replica group by range.

Parameters:
   Name                  Type  Info:
   source_group_name     str   The source replica group name.
   target_group_name     str   The target replica group name.
   split_condition       dict  The matching rule, return the count of
                             all documents if None.
   split_end_condition   dict  The split end condition or None.
                             eg:
                             If we create a collection with the
                             option { ShardingKey:{"age":1},
                             ShardingType:"Hash",Partition:2^10 },
                             we can fill {age:30} as the
                             splitCondition, and fill {age:60}
                             as the splitEndCondition. when split,
                             the target replica group will get the
                             records whose age's hash value are in
                             [30,60). If splitEndCondition is null,
                             they are in [30,max).
Return values:
   task id
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.split_async_by_percent (   self,
  source_group_name,
  target_group_name,
  percent 
)
Split the specified collection from source replica group to target
   replica group by percent.

Parameters:
   Name               Type     Info:
   source_group_name  str      The source replica group name.
   target_group_name  str      The target replica group name.
   percent                float    The split percent, Range:(0,100]
Return values:
   task id
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.split_by_condition (   self,
  source_group_name,
  target_group_name,
  split_condition,
  split_end_condition = None 
)
Split the specified collection from source replica group to target
   replica group by range.

Parameters:
   Name                  Type     Info:
   source_group_name     str      The source replica group name.
   target_group_name     str      The target replica group name.
   split_condition       dict     The matching rule, return the count
                                of all documents if None.
   split_end_condition   dict     The split end condition or None.
                                eg:
                                If we create a collection with the
                                option { ShardingKey:{"age":1},
                                ShardingType:"Hash",Partition:2^10 },
                                we can fill {age:30} as the
                                splitCondition, and fill {age:60}
                                as the splitEndCondition. when
                                split, the target replica group
                                will get the records whose age's
                                hash value are in [30,60).
                                If splitEndCondition is null, they
                                are in [30,max).
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.split_by_percent (   self,
  source_group_name,
  target_group_name,
  percent 
)
Split the specified collection from source replica group to target
   replica group by percent.

Parameters:
   Name               Type     Info:
   source_group_name  str      The source replica group name.
   target_group_name  str      The target replica group name.
   percent                float    The split percent, Range:(0,100]
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.truncate (   self)
truncate the collection.

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.truncate_lob (   self,
  oid,
  length 
)
truncate lob.

Parameters:
   Name     Type                 Info:
   oid      str/bson.ObjectId    The oid of the lob to be truncated.
   length   int/long             The truncate length
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.collection.collection.update (   self,
  rule,
  kwargs 
)
Update the matching documents in current collection.

Parameters:
   Name        Type     Info:
   rule        dict     The updating rule.
   **kwargs             Useful option are below
   - condition dict     The matching rule, match all the documents
                        if not provided.
   - hint      dict     The hint, automatically match the optimal hint
                        if not provided.
   - flags     int      See Info as below.
Return values:
    A dict object contains the update details. As follow:
    - UpdatedNum  : The number of records successfully updated, including records that match but have no
            data changes.
    - ModifiedNum : The number of records successfully updated with data changes.
    - InsertedNum : The number of records successfully inserted.
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   The update flags, default to be 0, it can choose the follow values:
     UPDATE_FLG_KEEP_SHARDINGKEY : The sharding key in update rule is not filtered, when executing
                                   update or upsert.
     UPDATE_FLG_UPDATE_ONE       : The flag represent whether to update only one matched record or all
                                   matched records.
Note:
   When flag is set to 0, it won't work to update the "ShardingKey" field, but the
   other fields take effect.
def pysequoiadb.collection.collection.upsert (   self,
  rule,
  kwargs 
)
Update the matching documents in current collection, insert if
   no matching.

Parameters:
   Name          Type  Info:
   rule          dict  The updating rule.
   **kwargs            Useful options are below
   - condition   dict  The matching rule, match all the documents
                       if not provided.
   - hint        dict  The hint, automatically match the optimal hint
                       if not provided.
   - setOnInsert dict  The setOnInsert assigns the specified values
                       to the fields when insert.
   - flags       int   See Info as below.
Return values:
    A dict object contains the upsert details. As follow:
    - UpdatedNum  : The number of records successfully updated, including records that match but have no
            data changes.
    - ModifiedNum : The number of records successfully updated with data changes.
    - InsertedNum : The number of records successfully inserted.
Exceptions:
   pysequoiadb.error.SDBBaseError
Info:
   The update flags, default to be 0, it can choose the follow values:
     UPDATE_FLG_KEEP_SHARDINGKEY : The sharding key in update rule is not filtered, when executing
                                   update or upsert.
     UPDATE_FLG_UPDATE_ONE       : The flag represent whether to update only one matched record or all
                                   matched records.
Note:
   When flag is set to 0, it won't work to update the "ShardingKey" field, but the
   other fields take effect.

The documentation for this class was generated from the following file: