Class Collection<T>
Represents a collection of documents with a generic type.
Namespace: MySqlX.XDevAPI
Assembly: MySql.Data.dll
Version: 9.1.0
Syntax
public class Collection<T> : DatabaseObject
Type Parameters
Name | Description |
---|---|
T |
Constructors
Collection(Schema, String)
Initializes a new instance of the generic Collection class based on the specified schema and name.
Declaration
public Collection(Schema s, string name)
Parameters
Type | Name | Description |
---|---|---|
Schema | s | The Schema object associated to this collection. |
System.String | name | The name of the collection. |
Methods
Add(Object[])
Creates an AddStatement<T> containing the provided generic object. The add statement can be further modified before execution.
Declaration
public AddStatement<T> Add(params object[] items)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | items | The generic object to add. |
Returns
Type | Description |
---|---|
AddStatement<T> | An AddStatement<T> object containing the object to add. |
Count()
Returns the number of documents in this collection on the server.
Declaration
public long Count()
Returns
Type | Description |
---|---|
System.Int64 | The number of documents found. |
CreateIndex(String, Object)
Creates an index based on the properties provided in the JSON document.
Declaration
public void CreateIndex(string indexName, object indexDefinition)
Parameters
Type | Name | Description |
---|---|---|
System.String | indexName | The index name. |
System.Object | indexDefinition | JSON document describing the index to be created. |
Remarks
indexDefinition
is a JSON document with the following fields:
- fields
: array of IndexField
objects, each describing a single document member to be
included in the index (see below).
- type: string
, (optional) the type of index. One of INDEX or SPATIAL. Default is INDEX and may
be omitted.
A single IndexField
description consists of the following fields:
- field
: string, the full document path to the document member or field to be indexed.
- type
: string, one of the supported SQL column types to map the field into (see the following list).
For numeric types, the optional UNSIGNED keyword may follow. For the TEXT type, the length to consider for
indexing may be added.
- required
: bool, (optional) true if the field is required to exist in the document. defaults to
false, except for GEOJSON where it defaults to true.
- options
: int, (optional) special option flags for use when decoding GEOJSON data.
- srid
: int, (optional) srid value for use when decoding GEOJSON data.
Supported SQL column types:
- INT [UNSIGNED]
- TINYINT [UNSIGNED]
- SMALLINT[UNSIGNED]
- MEDIUMINT [UNSIGNED]
- INTEGER [UNSIGNED]
- BIGINT [UNSIGNED]
- REAL [UNSIGNED]
- FLOAT [UNSIGNED]
- DOUBLE [UNSIGNED]
- DECIMAL [UNSIGNED]
- NUMERIC [UNSIGNED]
- DATE
- TIME
- TIMESTAMP
- DATETIME
- TEXT[(length)]
- CHAR[(lenght)]
- GEOJSON (extra options: options, srid)
DropIndex(String)
Drops a collection index.
Declaration
public void DropIndex(string indexName)
Parameters
Type | Name | Description |
---|---|---|
System.String | indexName | The index name. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
ExistsInDatabase()
Verifies if the current collection exists in the server schema.
Declaration
public override bool ExistsInDatabase()
Returns
Type | Description |
---|---|
System.Boolean |
|
Overrides
Find(String)
Creates a FindStatement<T> with the given condition which can be used to find documents in a collection.
Declaration
public FindStatement<T> Find(string condition = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | condition | An optional condition to match documents. |
Returns
Type | Description |
---|---|
FindStatement<T> | A FindStatement<T> object set with the given condition. |
Remarks
The statement can then be further modified before execution.
GetOne(Object)
Returns the document with the given identifier.
Declaration
public T GetOne(object id)
Parameters
Type | Name | Description |
---|---|---|
System.Object | id | The unique identifier of the document to replace. |
Returns
Type | Description |
---|---|
T | A |
Remarks
This is a direct execution method.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Modify(String)
Creates a ModifyStatement<T> with the given condition that can be used to modify one or more documents from a collection.
Declaration
public ModifyStatement<T> Modify(string condition)
Parameters
Type | Name | Description |
---|---|---|
System.String | condition | The condition to match documents. |
Returns
Type | Description |
---|---|
ModifyStatement<T> | A ModifyStatement<T> object set with the given condition. |
Remarks
The statement can then be further modified before execution.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Remove(String)
Creates a RemoveStatement<T> with the given condition that can be used to remove one or more documents from a collection.The statement can then be further modified before execution.
Declaration
public RemoveStatement<T> Remove(string condition)
Parameters
Type | Name | Description |
---|---|---|
System.String | condition | The condition to match documents. |
Returns
Type | Description |
---|---|
RemoveStatement<T> | A RemoveStatement<T> object set with the given condition. |
Remarks
The statement can then be further modified before execution.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
RemoveOne(Object)
Removes the document with the given identifier.
Declaration
public Result RemoveOne(object id)
Parameters
Type | Name | Description |
---|---|---|
System.Object | id | The unique identifier of the document to replace. |
Returns
Type | Description |
---|---|
Result | A Result object containing the results of the execution. |
Remarks
This is a direct execution method.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|