Search Results for

    Show / Hide Table of Contents

    Class Collection

    Represents a collection of documents.

    Inheritance
    System.Object
    DatabaseObject
    Collection<DbDoc>
    Collection
    Namespace: MySqlX.XDevAPI
    Assembly: MySql.Data.dll
    Version: 9.3.0
    Syntax
    public class Collection : Collection<DbDoc>

    Methods

    Add(Object[])

    Creates an AddStatement<T> containing the provided objects that can be used to add one or more items to a collection.

    Declaration
    public AddStatement<DbDoc> Add(params object[] items)
    Parameters
    Type Name Description
    System.Object[] items

    The objects to add.

    Returns
    Type Description
    AddStatement<DbDoc>

    An AddStatement<T> object containing the objects to add.

    Remarks

    This method can take anonymous objects, domain objects, or just plain JSON strings. The statement can be further modified before execution.

    Exceptions
    Type Condition
    System.ArgumentNullException

    items is null.

    AddOrReplaceOne(Object, Object)

    Adds the given document to the collection unless the identifier or any other field that has a unique index already exists, in which case it will update the matching document.

    Declaration
    public Result AddOrReplaceOne(object id, object doc)
    Parameters
    Type Name Description
    System.Object id

    The unique identifier of the document to replace.

    System.Object doc

    The document to replace the matching document.

    Returns
    Type Description
    Result

    A Result object containing the results of the execution.

    Remarks

    This is a direct execution method.

    Exceptions
    Type Condition
    MySqlException

    The server version is lower than 8.0.3.

    System.ArgumentNullException

    id is null or white space.

    System.ArgumentNullException

    doc is null.

    System.FormatException

    The id is different from the one in doc.

    Find(String)

    Creates a FindStatement<T> with the given condition, which can be used to find documents in a collection.

    Declaration
    public FindStatement<DbDoc> Find(string condition = null)
    Parameters
    Type Name Description
    System.String condition

    An optional condition to match documents.

    Returns
    Type Description
    FindStatement<DbDoc>

    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 DbDoc GetOne(object id)
    Parameters
    Type Name Description
    System.Object id

    The unique identifier of the document to replace.

    Returns
    Type Description
    DbDoc

    A DbDoc object if a document matching given identifier exists; otherwise, null.

    Remarks

    This is a direct execution method.

    Exceptions
    Type Condition
    System.ArgumentNullException

    id is null or white space.

    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<DbDoc> Modify(string condition)
    Parameters
    Type Name Description
    System.String condition

    The condition to match documents.

    Returns
    Type Description
    ModifyStatement<DbDoc>

    A ModifyStatement<T> object set with the given condition.

    Remarks

    The statement can then be further modified before execution.

    Exceptions
    Type Condition
    System.ArgumentNullException

    condition is null or white space.

    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<DbDoc> Remove(string condition)
    Parameters
    Type Name Description
    System.String condition

    The condition to match documents.

    Returns
    Type Description
    RemoveStatement<DbDoc>

    A RemoveStatement<T> object set with the given condition.

    Remarks

    The statement can then be further modified before execution.

    Exceptions
    Type Condition
    System.ArgumentNullException

    condition is null or white space.

    ReplaceOne(Object, Object)

    Replaces the document matching the given identifier.

    Declaration
    public Result ReplaceOne(object id, object doc)
    Parameters
    Type Name Description
    System.Object id

    The unique identifier of the document to replace.

    System.Object doc

    The document to replace the matching document.

    Returns
    Type Description
    Result

    A Result object containing the results of the execution.

    Remarks

    This is a direct execution method. Operation succeeds even if no matching document was found; in which case, the Result.RecordsAffected property is zero. If the new document contains an identifier, the value is ignored.

    Exceptions
    Type Condition
    System.ArgumentNullException

    id is null or whitespace.

    System.ArgumentNullException

    doc is null.

    In This Article
    • Methods
      • Add(Object[])
      • AddOrReplaceOne(Object, Object)
      • Find(String)
      • GetOne(Object)
      • Modify(String)
      • Remove(String)
      • ReplaceOne(Object, Object)
    Back to top Copyright © 2021, 2025, Oracle and/or its affiliates.