SequoiaDB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Public Attributes | List of all members
sdbclient::sdbCollection Class Reference

Database operation interfaces of collection. More...

#include <client.hpp>

Public Member Functions

 sdbCollection ()
 Default constructor.
 
 ~sdbCollection ()
 Destructor.
 
INT32 getCount (SINT64 &count, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject)
 Get the count of matching documents in current collection.
 
INT32 split (const CHAR *pSourceGroupName, const CHAR *pTargetGroupName, const bson::BSONObj &splitCondition, const bson::BSONObj &splitEndCondition=_sdbStaticObject)
 Split the specified collection from source replica group to target replica group by range.
 
INT32 split (const CHAR *pSourceGroupName, const CHAR *pTargetGroupName, FLOAT64 percent)
 Split the specified collection from source replica group to target replica group by percent.
 
INT32 splitAsync (SINT64 &taskID, const CHAR *pSourceGroupName, const CHAR *pTargetGroupName, const bson::BSONObj &splitCondition, const bson::BSONObj &splitEndCondition=_sdbStaticObject)
 Split the specified collection from source replica group to target replica group by range.
 
INT32 splitAsync (const CHAR *pSourceGroupName, const CHAR *pTargetGroupName, FLOAT64 percent, SINT64 &taskID)
 Split the specified collection from source replica group to target replica group by percent.
 
INT32 alterCollection (const bson::BSONObj &options)
 Alter the current collection.
 
INT32 insert (const bson::BSONObj &obj, INT32 flags, bson::BSONObj *pResult=NULL)
 Insert a bson object into current collection.
 
INT32 insert (std::vector< bson::BSONObj > &objs, INT32 flags=0, bson::BSONObj *pResult=NULL)
 Insert a bson object into current collection.
 
INT32 insert (const bson::BSONObj objs[], INT32 size, INT32 flags=0, bson::BSONObj *pResult=NULL)
 Insert bson objects into current collection.
 
INT32 bulkInsert (SINT32 flags, std::vector< bson::BSONObj > &objs)
 Insert a bulk of bson objects into current collection.
 
INT32 update (const bson::BSONObj &rule, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT32 flag=0, bson::BSONObj *pResult=NULL)
 Update the matching documents in current collection.
 
INT32 upsert (const bson::BSONObj &rule, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, const bson::BSONObj &setOnInsert=_sdbStaticObject, INT32 flag=0, bson::BSONObj *pResult=NULL)
 Update the matching documents in current collection, insert if no matching.
 
INT32 del (const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT32 flag=0, bson::BSONObj *pResult=NULL)
 Delete the matching documents in current collection.
 
INT32 query (sdbCursor &cursor, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &selected=_sdbStaticObject, const bson::BSONObj &orderBy=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT64 numToSkip=0, INT64 numToReturn=-1, INT32 flags=0)
 Get the matching documents in current collection.
 
INT32 queryOne (bson::BSONObj &obj, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &selected=_sdbStaticObject, const bson::BSONObj &orderBy=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT64 numToSkip=0, INT32 flag=0)
 Get the first matching documents in current collection.
 
INT32 queryAndUpdate (sdbCursor &cursor, const bson::BSONObj &update, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &selected=_sdbStaticObject, const bson::BSONObj &orderBy=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT64 numToSkip=0, INT64 numToReturn=-1, INT32 flag=0, BOOLEAN returnNew=FALSE)
 Get the matching documents in current collection and update.
 
INT32 queryAndRemove (sdbCursor &cursor, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &selected=_sdbStaticObject, const bson::BSONObj &orderBy=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT64 numToSkip=0, INT64 numToReturn=-1, INT32 flag=0)
 Get the matching documents in current collection and remove.
 
INT32 createIndex (const bson::BSONObj &indexDef, const CHAR *pIndexName, BOOLEAN isUnique, BOOLEAN isEnforced, INT32 sortBufferSize=SDB_INDEX_SORT_BUFFER_DEFAULT_SIZE)
 Create the index in current collection.
 
INT32 createIndex (const bson::BSONObj &indexDef, const CHAR *pIndexName, const bson::BSONObj &options)
 Create the index in current collection.
 
INT32 getIndexes (sdbCursor &cursor, const CHAR *pIndexName)
 Get all of or one of the indexes in current collection.
 
INT32 getIndexes (std::vector< bson::BSONObj > &infos)
 Get all of the indexes in current collection.
 
INT32 getIndex (const CHAR *pIndexName, bson::BSONObj &info)
 Get the specified index in current collection.
 
INT32 dropIndex (const CHAR *pIndexName)
 Drop the index in current collection.
 
INT32 create ()
 create the specified collection of current collection space
 
INT32 drop ()
 Drop the specified collection of current collection space.
 
const CHAR * getCollectionName ()
 Get the name of specified collection in current collection space.
 
const CHAR * getCSName ()
 Get the name of current collection space.
 
const CHAR * getFullName ()
 Get the full name of specified collection in current collection space.
 
INT32 aggregate (sdbCursor &cursor, std::vector< bson::BSONObj > &obj)
 Execute aggregate operation in specified collection.
 
INT32 getQueryMeta (sdbCursor &cursor, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &orderBy=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT64 numToSkip=0, INT64 numToReturn=-1)
 Get the index blocks' or data blocks' infomations for concurrent query.
 
INT32 attachCollection (const CHAR *subClFullName, const bson::BSONObj &options)
 Attach the specified collection.
 
INT32 detachCollection (const CHAR *subClFullName)
 Dettach the specified collection.
 
INT32 explain (sdbCursor &cursor, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &select=_sdbStaticObject, const bson::BSONObj &orderBy=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT64 numToSkip=0, INT64 numToReturn=-1, INT32 flag=0, const bson::BSONObj &options=_sdbStaticObject)
 Get access plan of query.
 
INT32 createLob (sdbLob &lob, const bson::OID *oid=NULL)
 Create large object.
 
INT32 removeLob (const bson::OID &oid)
 Remove large object.
 
INT32 truncateLob (const bson::OID &oid, INT64 length)
 truncate large object to specified length.
 
INT32 openLob (sdbLob &lob, const bson::OID &oid, SDB_LOB_OPEN_MODE mode=SDB_LOB_READ)
 Open an existing large object for reading or writing.
 
INT32 listLobs (sdbCursor &cursor, const bson::BSONObj &condition=_sdbStaticObject, const bson::BSONObj &selected=_sdbStaticObject, const bson::BSONObj &orderBy=_sdbStaticObject, const bson::BSONObj &hint=_sdbStaticObject, INT64 numToSkip=0, INT64 numToReturn=-1)
 List the lobs' meta data in current collection.
 
INT32 createLobID (bson::OID &oid, const CHAR *pTimeStamp=NULL)
 
INT32 truncate ()
 truncate the collection
 
INT32 createIdIndex (const bson::BSONObj &options=_sdbStaticObject)
 Create $id index in collection.
 
INT32 dropIdIndex ()
 Drop $id index in collection.
 
INT32 createAutoIncrement (const bson::BSONObj &options)
 Create an autoincrement field on collection.
 
INT32 createAutoIncrement (const std::vector< bson::BSONObj > &options)
 Create a bulk of autoincrement fields on collection.
 
INT32 dropAutoIncrement (const CHAR *fieldName)
 Drop an autoincrement field on collection.
 
INT32 dropAutoIncrement (const std::vector< const CHAR * > &fieldNames)
 Drop a bulk of autoincrement fields on collection.
 
INT32 enableSharding (const bson::BSONObj &options=_sdbStaticObject)
 Alter the current collection to enable sharding.
 
INT32 disableSharding ()
 Alter the current collection to disable sharding.
 
INT32 enableCompression (const bson::BSONObj &options=_sdbStaticObject)
 Alter the current collection to enable compression.
 
INT32 disableCompression ()
 Alter the current collection to disable compression.
 
INT32 setAttributes (const bson::BSONObj &options)
 Alter the current collection.
 
INT32 getDetail (sdbCursor &cursor)
 Get the detail of the collection.
 

Public Attributes

_sdbCollection * pCollection
 

Detailed Description

Database operation interfaces of collection.

Member Function Documentation

INT32 sdbclient::sdbCollection::aggregate ( sdbCursor cursor,
std::vector< bson::BSONObj > &  obj 
)
inline

Execute aggregate operation in specified collection.

Parameters
[in]objThe array of bson objects
[out]cursorThe cursor object of result
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::alterCollection ( const bson::BSONObj &  options)
inline

Alter the current collection.

Parameters
[in]optionsThe modified options as following:
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
               e.g. {RepliSize:0, ShardingKey:{a:1}, ShardingType:"hash", Partition:1024}
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}]}
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::attachCollection ( const CHAR *  subClFullName,
const bson::BSONObj &  options 
)
inline

Attach the specified collection.

Parameters
[in]subClFullNameThe name of the subcollection
[in]optionsPartition range
LowBound: low boudary
          eg: "LowBound":{a:1}
UpBound: up boudary
         eg: { "UpBound":{a:100} }
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::bulkInsert ( SINT32  flags,
std::vector< bson::BSONObj > &  objs 
)
inline

Insert a bulk of bson objects into current collection.

Parameters
[in]flagsThe flag to control the behavior of inserting. The value of flag default to be 0, and it can choose the follow values:
  • 0: while 0 is set(default to be 0), database will stop inserting when some records hit index key duplicate error.
  • FLG_INSERT_CONTONDUP: if some records hit index key duplicate error, database will skip them and go on inserting.
  • FLG_INSERT_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.

[in]objsThe bson objects to be inserted.
Return values
SDB_OKOperation Success.
OthersOperation Fail.
INT32 sdbclient::sdbCollection::create ( )
inline

create the specified collection of current collection space

Deprecated:
This function will be deprecated in SequoiaDB1.6, use sdbCollectionSpace::createCollection instead of it.
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::createAutoIncrement ( const bson::BSONObj &  options)
inline

Create an autoincrement field on collection.

Parameters
[in]optionsThe options as following:
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
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::createAutoIncrement ( const std::vector< bson::BSONObj > &  options)
inline

Create a bulk of autoincrement fields on collection.

Parameters
[in]optionsThe option array of autoincrement fields
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::createIdIndex ( const bson::BSONObj &  options = _sdbStaticObject)
inline

Create $id index in collection.

Parameters
[in]optionsThe arguments of creating id index.e.g.{SortBufferSize:64}
SortBufferSize     : The size of sort buffer used when creating index, the unit is MB,
                     zero means don't use sort buffer
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::createIndex ( const bson::BSONObj &  indexDef,
const CHAR *  pIndexName,
BOOLEAN  isUnique,
BOOLEAN  isEnforced,
INT32  sortBufferSize = SDB_INDEX_SORT_BUFFER_DEFAULT_SIZE 
)
inline

Create the index in current collection.

Parameters
[in]indexDefThe bson structure of index element, e.g. {name:1, age:-1}
[in]pIndexNameThe index name
[in]isUniqueWhether the index elements are unique or not
[in]isEnforcedWhether the index is enforced unique This element is meaningful when isUnique is set to true
[in]sortBufferSizeThe size of sort buffer used when creating index, the unit is MB, zero means don't use sort buffer
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::createIndex ( const bson::BSONObj &  indexDef,
const CHAR *  pIndexName,
const bson::BSONObj &  options 
)
inline

Create the index in current collection.

Parameters
[in]indexDefThe bson structure of index element, e.g. {name:1, age:-1}
[in]pIndexNameThe index name
[in]optionsThe options are as below:
Unique:    Whether the index elements are unique or not
Enforced:  Whether the index is enforced unique.
           This element is meaningful when Unique is true
NotNull:   Any field of index key should exist and cannot be null when NotNull is true
SortBufferSize: The size of sort buffer used when creating index.
                Unit is MB. Zero means don't use sort buffer
NotArray:  Any field of index not support array when NotArray is true
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::createLob ( sdbLob lob,
const bson::OID *  oid = NULL 
)
inline

Create large object.

Parameters
[in]oidThe id of the large object
[out]lobThe newly create large object
Return values
SDB_OKOperation Success
OthersOperation Fail
Note
When oid is offered, use it to create a lob for writing, otherwise, API will generate one. After finish writing the newly created lob, need to close it to release resource.
INT32 sdbclient::sdbCollection::createLobID ( bson::OID &  oid,
const CHAR *  pTimestamp = NULL 
)
inline
Parameters
[in]pTimestamppoint of Timestamp(format:YYYY-MM-DD-HH.mm.ss). if Timestamp is NULL the Timestamp will be generated by server
[out]oidThe oid generated by server
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::del ( const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
INT32  flag = 0,
bson::BSONObj *  pResult = NULL 
)
inline

Delete the matching documents in current collection.

Parameters
[in]conditionThe matching rule, delete all the documents if not provided
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]flagReserved
[out]pResultThe detail result for deleting
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::detachCollection ( const CHAR *  subClFullName)
inline

Dettach the specified collection.

Parameters
[in]subClFullNameThe name of the subcollection
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::disableCompression ( )
inline

Alter the current collection to disable compression.

Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::disableSharding ( )
inline

Alter the current collection to disable sharding.

Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::drop ( )
inline

Drop the specified collection of current collection space.

Deprecated:
This function will be deprecated in SequoiaDB1.6, use sdbCollectionSpace::dropCollection instead of it.
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::dropAutoIncrement ( const CHAR *  fieldName)
inline

Drop an autoincrement field on collection.

Parameters
[in]fieldNameThe name of autoincrement field
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::dropAutoIncrement ( const std::vector< const CHAR * > &  fieldNames)
inline

Drop a bulk of autoincrement fields on collection.

Parameters
[in]fieldNamesThe array of autoincrement field names
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::dropIdIndex ( )
inline

Drop $id index in collection.

Return values
SDB_OKOperation Success
OthersOperation Fail
Note
delete, update and upsert do not work after index "$id" was drop
INT32 sdbclient::sdbCollection::dropIndex ( const CHAR *  pIndexName)
inline

Drop the index in current collection.

Parameters
[in]pIndexNameThe index name
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::enableCompression ( const bson::BSONObj &  options = _sdbStaticObject)
inline

Alter the current collection to enable compression.

Parameters
[in]optionsThe modified options as following:
CompressionType : The compression type of data, could be "snappy" or "lzw"
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::enableSharding ( const bson::BSONObj &  options = _sdbStaticObject)
inline

Alter the current collection to enable sharding.

Parameters
[in]optionsThe modified options as following:
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
Note
Can't alter attributes about split in partition collection; After altering a collection to be a partition collection, need to split this collection manually
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::explain ( sdbCursor cursor,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  select = _sdbStaticObject,
const bson::BSONObj &  orderBy = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
INT64  numToSkip = 0,
INT64  numToReturn = -1,
INT32  flag = 0,
const bson::BSONObj &  options = _sdbStaticObject 
)
inline

Get access plan of query.

Parameters
[in]conditionThe matching rule, return all the documents if null
[in]selectThe selective rule, return the whole document if null
[in]orderByThe ordered rule, never sort if null
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]numToSkipSkip the first numToSkip documents, never skip if this parameter is 0
[in]numToReturnOnly return numToReturn documents, return all if this parameter is -1
[in]flagThe query flag, default to be 0. Please see the definition of follow flags for more detail. Usage: e.g. set ( QUERY_FORCE_HINT | QUERY_WITH_RETURNDATA ) to param flag
[in]optionsthe rules of explain, the options are as below:
Run     : Whether execute query explain or not, true for excuting query explain then get
          the data and time information; false for not excuting query explain but get the
          query explain information only. e.g. {Run:true}
[out]cursorThe cursor of current query
Return values
SDB_OKOperation Success
OthersOperation Fail
const CHAR * sdbclient::sdbCollection::getCollectionName ( )
inline

Get the name of specified collection in current collection space.

Returns
The name of specified collection.
INT32 sdbclient::sdbCollection::getCount ( SINT64 &  count,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject 
)
inline

Get the count of matching documents in current collection.

Parameters
[in]conditionThe matching rule, return the count of all documents if this parameter is empty
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[out]countThe count of matching documents, matches all records if not provided.
Return values
SDB_OKOperation Success
OthersOperation Fail
const CHAR * sdbclient::sdbCollection::getCSName ( )
inline

Get the name of current collection space.

Returns
The name of current collection space.
INT32 sdbclient::sdbCollection::getDetail ( sdbCursor cursor)
inline

Get the detail of the collection.

Parameters
[out]cursorReturn the all the info of current collection.
Return values
SDB_OKOperation Success
OthersOperation Fail
const CHAR * sdbclient::sdbCollection::getFullName ( )
inline

Get the full name of specified collection in current collection space.

Returns
The full name of specified collection.
INT32 sdbclient::sdbCollection::getIndex ( const CHAR *  pIndexName,
bson::BSONObj &  info 
)
inline

Get the specified index in current collection.

Parameters
[in]pIndexNameThe index name, returns all of the indexes if this parameter is null
[out]infoThe information of the index.
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::getIndexes ( sdbCursor cursor,
const CHAR *  pIndexName 
)
inline

Get all of or one of the indexes in current collection.

Parameters
[in]pIndexNameThe index name, returns all of the indexes if this parameter is null
[out]cursorThe cursor of all the result for current query.
Deprecated:
Use the other overloaded versions instead.
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::getIndexes ( std::vector< bson::BSONObj > &  infos)
inline

Get all of the indexes in current collection.

Parameters
[out]infosVector for the information of all the index.
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::getQueryMeta ( sdbCursor cursor,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  selected = _sdbStaticObject,
const bson::BSONObj &  orderBy = _sdbStaticObject,
INT64  numToSkip = 0,
INT64  numToReturn = -1 
)
inline

Get the index blocks' or data blocks' infomations for concurrent query.

Parameters
[in]conditionThe matching rule, return the whole range of index blocks if not provided eg:{"age":{"$gt":25},"age":{"$lt":75}}
[in]orderByThe ordered rule, result set is unordered if not provided
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]numToSkipSkip the first numToSkip documents, default is 0
[in]numToReturnOnly return numToReturn documents, default is -1 for returning all results
[out]cursorThe result of query
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::insert ( const bson::BSONObj &  obj,
INT32  flags,
bson::BSONObj *  pResult = NULL 
)
inline

Insert a bson object into current collection.

Parameters
[in]objThe bson object to be inserted.
[in]flagsThe flag to control the behavior of inserting. The value of flag default to be 0, and it can choose the follow values:
  • 0: while 0 is set(default to be 0), database will stop inserting when some records hit index key duplicate error.
  • FLG_INSERT_CONTONDUP: if some records hit index key duplicate error, database will skip them and go on inserting.
  • FLG_INSERT_RETURN_OID: return the value of "_id" field in the record.
  • FLG_INSERT_REPLACEONDUP: if the record hit index key duplicate error, database will replace the existing record by the inserting new record.
[out]pResultThe result of inserting. Can be NULL or a bson:
  • NULL: when this argument is NULL.
  • empty bson: when this argument is not NULL but there is no result return.
  • bson which contains the "_id" field: when flag "FLG_INSERT_RETURN_OID" is set, return the value of "_id" field of the inserted record. e.g.: { "_id": { "$oid": "5c456e8eb17ab30cfbf1d5d1" } }
Return values
SDB_OKOperation Success.
OthersOperation Fail.
INT32 sdbclient::sdbCollection::insert ( std::vector< bson::BSONObj > &  objs,
INT32  flags = 0,
bson::BSONObj *  pResult = NULL 
)
inline

Insert a bson object into current collection.

Parameters
[in]objsThe bson objects to be inserted.
[in]flagsThe flag to control the behavior of inserting. The value of flag default to be 0, and it can choose the follow values:
  • 0: while 0 is set(default to be 0), database will stop inserting when some records hit index key duplicate error.
  • FLG_INSERT_CONTONDUP: if some records hit index key duplicate error, database will skip them and go on inserting.
  • FLG_INSERT_RETURN_OID: return the value of "_id" field in the record.
  • FLG_INSERT_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.

[out]pResultThe result of inserting. Can be NULL or a bson:
  • NULL: when this argument is NULL.
  • empty bson: when this argument is not NULL but there is no result return.
  • bson which contains the field "_id": when flag "FLG_INSERT_RETURN_OID" is set, return all the values of "_id" field in a bson array. e.g.: { "_id": [ { "$oid": "5c456e8eb17ab30cfbf1d5d1" }, { "$oid": "5c456e8eb17ab30cfbf1d5d2" } ] }
Return values
SDB_OKOperation Success.
OthersOperation Fail.
INT32 sdbclient::sdbCollection::insert ( const bson::BSONObj  objs[],
INT32  size,
INT32  flags = 0,
bson::BSONObj *  pResult = NULL 
)
inline

Insert bson objects into current collection.

Parameters
[in]objsThe array of bson objects to be inserted.
[in]sizeThe size of the array.
[in]flagsThe flag to control the behavior of inserting. The value of flag default to be 0, and it can choose the follow values:
  • 0: while 0 is set(default to be 0), database will stop inserting when some records hit index key duplicate error.
  • FLG_INSERT_CONTONDUP: if some records hit index key duplicate error, database will skip them and go on inserting.
  • FLG_INSERT_RETURN_OID: return the value of "_id" field in the records.
  • FLG_INSERT_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.

[out]pResultThe result of inserting. Can be NULL or a bson:
  • NULL: when this argument is NULL.
  • empty bson: when this argument is not NULL but there is no result return.
  • bson which contains the "_id" field: when flag "FLG_INSERT_RETURN_OID" is set, return all the values of "_id" field in a bson array. e.g.: { "_id": [ { "$oid": "5c456e8eb17ab30cfbf1d5d1" }, { "$oid": "5c456e8eb17ab30cfbf1d5d2" } ] }
Return values
SDB_OKOperation Success.
OthersOperation Fail.
INT32 sdbclient::sdbCollection::listLobs ( sdbCursor cursor,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  selected = _sdbStaticObject,
const bson::BSONObj &  orderBy = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
INT64  numToSkip = 0,
INT64  numToReturn = -1 
)
inline

List the lobs' meta data in current collection.

Parameters
[in]conditionThe matching rule, return all the lob if not provided
[in]selectedThe selective rule, return the whole infomation if not provided
[in]orderByThe ordered rule, result set is unordered if not provided
[in]hintSpecified options. e.g. {"ListPieces": 1} means get the detail piece info of lobs;
[in]numToSkipSkip the first numToSkip lob, default is 0
[in]numToReturnOnly return numToReturn lob, default is -1 for returning all results
[out]cursorThe curosr reference of the result
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::openLob ( sdbLob lob,
const bson::OID &  oid,
SDB_LOB_OPEN_MODE  mode = SDB_LOB_READ 
)
inline

Open an existing large object for reading or writing.

Parameters
[in]oidThe id of the large object
[out]lobThe large object to get
[in]lobopen mode, should be SDB_LOB_READ or SDB_LOB_WRITE
Return values
SDB_OKOperation Success
OthersOperation Fail
Note
Need to close lob to release resource, after opening a lob.
INT32 sdbclient::sdbCollection::query ( sdbCursor cursor,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  selected = _sdbStaticObject,
const bson::BSONObj &  orderBy = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
INT64  numToSkip = 0,
INT64  numToReturn = -1,
INT32  flag = 0 
)
inline

Get the matching documents in current collection.

Parameters
[in]conditionThe matching rule, return all the documents if not provided
[in]selectedThe selective rule, return the whole document if not provided
[in]orderByThe ordered rule, result set is unordered if not provided
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]numToSkipSkip the first numToSkip documents, default is 0
[in]numToReturnOnly return numToReturn documents, default is -1 for returning all results
[in]flagThe query flag, default to be 0. Please see the definition of follow flags for more detail. Usage: e.g. set ( QUERY_FORCE_HINT | QUERY_WITH_RETURNDATA ) to param flag
[out]cursorThe cursor of current query
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::queryAndRemove ( sdbCursor cursor,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  selected = _sdbStaticObject,
const bson::BSONObj &  orderBy = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
INT64  numToSkip = 0,
INT64  numToReturn = -1,
INT32  flag = 0 
)
inline

Get the matching documents in current collection and remove.

Parameters
[in]conditionThe matching rule, return all the documents if not provided
[in]selectedThe selective rule, return the whole document if not provided
[in]orderByThe ordered rule, result set is unordered if not provided
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]numToSkipSkip the first numToSkip documents, default is 0
[in]numToReturnOnly return numToReturn documents, default is -1 for returning all results
[in]flagThe query flag, default to be 0. Please see the definition of follow flags for more detail. Usage: e.g. set ( QUERY_FORCE_HINT | QUERY_WITH_RETURNDATA ) to param flag
[out]cursorThe cursor of current query
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::queryAndUpdate ( sdbCursor cursor,
const bson::BSONObj &  update,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  selected = _sdbStaticObject,
const bson::BSONObj &  orderBy = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
INT64  numToSkip = 0,
INT64  numToReturn = -1,
INT32  flag = 0,
BOOLEAN  returnNew = FALSE 
)
inline

Get the matching documents in current collection and update.

Parameters
[in]updateThe update rule, can't be empty
[in]conditionThe matching rule, return all the documents if not provided
[in]selectedThe selective rule, return the whole document if not provided
[in]orderByThe ordered rule, result set is unordered if not provided
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]numToSkipSkip the first numToSkip documents, default is 0
[in]numToReturnOnly return numToReturn documents, default is -1 for returning all results
[in]flagThe query flag, default to be 0. Please see the definition of follow flags for more detail. Usage: e.g. set ( QUERY_FORCE_HINT | QUERY_WITH_RETURNDATA ) to param flag
[in]returnNewWhen TRUE, returns the updated document rather than the original
[out]cursorThe cursor of current query
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::queryOne ( bson::BSONObj &  obj,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  selected = _sdbStaticObject,
const bson::BSONObj &  orderBy = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
INT64  numToSkip = 0,
INT32  flag = 0 
)
inline

Get the first matching documents in current collection.

Parameters
[in]conditionThe matching rule, return all the documents if not provided
[in]selectedThe selective rule, return the whole document if not provided
[in]orderByThe ordered rule, result set is unordered if not provided
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]numToSkipSkip the first numToSkip documents, default is 0
[in]flagThe query flag, default to be 0. Please see the definition of follow flags for more detail. Usage: e.g. set ( QUERY_FORCE_HINT | QUERY_WITH_RETURNDATA ) to param flag
[out]objThe first matching object
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::removeLob ( const bson::OID &  oid)
inline

Remove large object.

Parameters
[in]oidThe id of the large object
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::setAttributes ( const bson::BSONObj &  options)
inline

Alter the current collection.

Parameters
[in]optionsThe modified options as following:
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
               e.g. {RepliSize:0, ShardingKey:{a:1}, ShardingType:"hash", Partition:1024}
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}]}
Note
Can't alter attributes about split in partition collection; After altering a collection to be a partition collection, need to split this collection manually
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::split ( const CHAR *  pSourceGroupName,
const CHAR *  pTargetGroupName,
const bson::BSONObj &  splitCondition,
const bson::BSONObj &  splitEndCondition = _sdbStaticObject 
)
inline

Split the specified collection from source replica group to target replica group by range.

Parameters
[in]pSourceGroupNameThe source replica group name
[in]pTargetGroupNameThe target replica group name
[in]splitConditionThe split condition
[in]splitEndConditionThe split end condition or null 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
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::split ( const CHAR *  pSourceGroupName,
const CHAR *  pTargetGroupName,
FLOAT64  percent 
)
inline

Split the specified collection from source replica group to target replica group by percent.

Parameters
[in]pSourceGroupNameThe source replica group name
[in]pTargetGroupNameThe target replica group name
[in]percentThe split percent, Range:(0,100]
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::splitAsync ( SINT64 &  taskID,
const CHAR *  pSourceGroupName,
const CHAR *  pTargetGroupName,
const bson::BSONObj &  splitCondition,
const bson::BSONObj &  splitEndCondition = _sdbStaticObject 
)
inline

Split the specified collection from source replica group to target replica group by range.

Parameters
[out]taskIDThe id of current split task
[in]pSourceGroupNameThe source replica group name
[in]pTargetGroupNameThe target replica group name
[in]splitConditionThe split condition
[in]splitEndConditionThe split end condition or null 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
SDB_OKOperation Success
OthersOperation Fail
INT32 INT32 sdbclient::sdbCollection::splitAsync ( const CHAR *  pSourceGroup,
const CHAR *  pTargetGroup,
FLOAT64  percent,
SINT64 &  taskID 
)
inline

Split the specified collection from source replica group to target replica group by percent.

Parameters
[in]pSourceGroupNameThe source replica group name
[in]pTargetGroupNameThe target replica group name
[in]percentThe split percent, Range:(0.0, 100.0]
[out]taskIDThe id of current split task
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::truncate ( )
inline

truncate the collection

Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::truncateLob ( const bson::OID &  oid,
INT64  length 
)
inline

truncate large object to specified length.

Parameters
[in]oidThe id of the large object
[in]lengthThe truncate length
Return values
SDB_OKOperation Success
OthersOperation Fail
INT32 sdbclient::sdbCollection::update ( const bson::BSONObj &  rule,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
INT32  flag = 0,
bson::BSONObj *  pResult = NULL 
)
inline

Update the matching documents in current collection.

Parameters
[in]ruleThe updating rule
[in]conditionThe matching rule, update all the documents if not provided
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]flagThe update flag, default to be 0. Please see the definition of follow flags for more detail
[out]pResultThe detail result for updating.
Return values
SDB_OKOperation Success
OthersOperation Fail
Note
When flag is set to 0, it won't work to update the "ShardingKey" field, but the other fields take effect
INT32 sdbclient::sdbCollection::upsert ( const bson::BSONObj &  rule,
const bson::BSONObj &  condition = _sdbStaticObject,
const bson::BSONObj &  hint = _sdbStaticObject,
const bson::BSONObj &  setOnInsert = _sdbStaticObject,
INT32  flag = 0,
bson::BSONObj *  pResult = NULL 
)
inline

Update the matching documents in current collection, insert if no matching.

Parameters
[in]ruleThe updating rule
[in]conditionThe matching rule, update all the documents if not provided
[in]hintSpecified the index used to scan data. e.g. {"":"ageIndex"} means using index "ageIndex" to scan data(index scan); {"":null} means table scan. when hint is not provided, database automatically match the optimal index to scan data
[in]setOnInsertThe setOnInsert assigns the specified values to the fileds when insert
[in]flagThe upsert flag, default to be 0. Please see the definition of follow flags for more detail
[out]pResultThe detail result for upserting
Return values
SDB_OKOperation Success
OthersOperation Fail
Note
When flag is set to 0, it won't work to update the "ShardingKey" field, but the other fields take effect

Member Data Documentation

sdbclient::sdbCollection::pCollection

A pointer of virtual base class _sdbCollection

Class sdbCollection is a shell for _sdbCollection. We use pCollection to call the methods in class _sdbCollection.


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