RLMMongoCollection

@interface RLMMongoCollection : NSObject

The RLMMongoCollection represents a MongoDB collection.

You can get an instance from a RLMMongoDatabase.

Create, read, update, and delete methods are available.

Operations against the Realm Cloud server are performed asynchronously.

Note

Before you can read or write data, a user must log in.
  • Usage: RLMMongoClient *client = [self.app mongoClient:@“mongodb1”]; RLMMongoDatabase *database = [client databaseWithName:@“test_data”]; RLMMongoCollection *collection = [database collectionWithName:@“Dog”]; [collection insertOneDocument:@{@“name”: @“fido”, @“breed”: @“cane corso”} completion:…];

  • The name of this mongodb collection.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSString *_Nonnull name;

    Swift

    var name: String { get }
  • Encodes the provided value to BSON and inserts it. If the value is missing an identifier, one will be generated for it.

    Declaration

    Objective-C

    - (void)insertOneDocument:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)document
                   completion:(nonnull RLMMongoInsertBlock)completion;

    Parameters

    document

    A Document value to insert.

    completion

    The result of attempting to perform the insert. An Id will be returned for the inserted object on sucess

  • Encodes the provided values to BSON and inserts them. If any values are missing identifiers, they will be generated.

    Declaration

    Objective-C

    - (void)insertManyDocuments:
                (nonnull NSArray<NSDictionary<NSString *, id<RLMBSON>> *> *)
                    documents
                     completion:(nonnull RLMMongoInsertManyBlock)completion;

    Parameters

    documents

    The Document values in a bson array to insert.

    completion

    The result of the insert, returns an array inserted document ids in order

  • Finds the documents in this collection which match the provided filter.

    Declaration

    Objective-C

    - (void)findWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
              options:(nonnull RLMFindOptions *)options
           completion:(nonnull RLMMongoFindBlock)completion;

    Parameters

    filterDocument

    A Document as bson that should match the query.

    options

    RLMFindOptions to use when executing the command.

    completion

    The resulting bson array of documents or error if one occurs

  • Finds the documents in this collection which match the provided filter.

    Declaration

    Objective-C

    - (void)findWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
           completion:(nonnull RLMMongoFindBlock)completion;

    Parameters

    filterDocument

    A Document as bson that should match the query.

    completion

    The resulting bson array as a string or error if one occurs

  • Returns one document from a collection or view which matches the provided filter. If multiple documents satisfy the query, this method returns the first document according to the query’s sort order or natural order.

    Declaration

    Objective-C

    - (void)findOneDocumentWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                         options:(nonnull RLMFindOptions *)options
                      completion:(nonnull RLMMongoFindOneBlock)completion;

    Parameters

    filterDocument

    A Document as bson that should match the query.

    options

    RLMFindOptions to use when executing the command.

    completion

    The resulting bson or error if one occurs

  • Returns one document from a collection or view which matches the provided filter. If multiple documents satisfy the query, this method returns the first document according to the query’s sort order or natural order.

    Declaration

    Objective-C

    - (void)findOneDocumentWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                      completion:(nonnull RLMMongoFindOneBlock)completion;

    Parameters

    filterDocument

    A Document as bson that should match the query.

    completion

    The resulting bson or error if one occurs

  • Runs an aggregation framework pipeline against this collection.

    Declaration

    Objective-C

    - (void)aggregateWithPipeline:
                (nonnull NSArray<NSDictionary<NSString *, id<RLMBSON>> *> *)pipeline
                       completion:(nonnull RLMMongoFindBlock)completion;

    Parameters

    pipeline

    A bson array made up of Documents containing the pipeline of aggregation operations to perform.

    completion

    The resulting bson array of documents or error if one occurs

  • Counts the number of documents in this collection matching the provided filter.

    Declaration

    Objective-C

    - (void)countWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                 limit:(NSInteger)limit
            completion:(nonnull RLMMongoCountBlock)completion;

    Parameters

    filterDocument

    A Document as bson that should match the query.

    limit

    The max amount of documents to count

    completion

    Returns the count of the documents that matched the filter.

  • Counts the number of documents in this collection matching the provided filter.

    Declaration

    Objective-C

    - (void)countWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
            completion:(nonnull RLMMongoCountBlock)completion;

    Parameters

    filterDocument

    A Document as bson that should match the query.

    completion

    Returns the count of the documents that matched the filter.

  • Deletes a single matching document from the collection.

    Declaration

    Objective-C

    - (void)deleteOneDocumentWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                        completion:(nonnull RLMMongoCountBlock)completion;

    Parameters

    filterDocument

    A Document as bson that should match the query.

    completion

    The result of performing the deletion. Returns the count of deleted objects

  • Deletes multiple documents

    Declaration

    Objective-C

    - (void)deleteManyDocumentsWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                          completion:(nonnull RLMMongoCountBlock)completion;

    Parameters

    filterDocument

    Document representing the match criteria

    completion

    The result of performing the deletion. Returns the count of the deletion

  • Updates a single document matching the provided filter in this collection.

    Declaration

    Objective-C

    - (void)updateOneDocumentWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                    updateDocument:(nonnull NSDictionary<NSString *, id<RLMBSON>> *)
                                       updateDocument
                            upsert:(BOOL)upsert
                        completion:(nonnull RLMMongoUpdateBlock)completion;

    Parameters

    filterDocument

    A bson Document representing the match criteria.

    updateDocument

    A bson Document representing the update to be applied to a matching document.

    upsert

    When true, creates a new document if no document matches the query.

    completion

    The result of the attempt to update a document.

  • Updates a single document matching the provided filter in this collection.

    Declaration

    Objective-C

    - (void)updateOneDocumentWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                    updateDocument:(nonnull NSDictionary<NSString *, id<RLMBSON>> *)
                                       updateDocument
                        completion:(nonnull RLMMongoUpdateBlock)completion;

    Parameters

    filterDocument

    A bson Document representing the match criteria.

    updateDocument

    A bson Document representing the update to be applied to a matching document.

    completion

    The result of the attempt to update a document.

  • Updates multiple documents matching the provided filter in this collection.

    Declaration

    Objective-C

    - (void)updateManyDocumentsWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                      updateDocument:
                          (nonnull NSDictionary<NSString *, id<RLMBSON>> *)
                              updateDocument
                              upsert:(BOOL)upsert
                          completion:(nonnull RLMMongoUpdateBlock)completion;

    Parameters

    filterDocument

    A bson Document representing the match criteria.

    updateDocument

    A bson Document representing the update to be applied to a matching document.

    upsert

    When true, creates a new document if no document matches the query.

    completion

    The result of the attempt to update a document.

  • Updates multiple documents matching the provided filter in this collection.

    Declaration

    Objective-C

    - (void)updateManyDocumentsWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                      updateDocument:
                          (nonnull NSDictionary<NSString *, id<RLMBSON>> *)
                              updateDocument
                          completion:(nonnull RLMMongoUpdateBlock)completion;

    Parameters

    filterDocument

    A bson Document representing the match criteria.

    updateDocument

    A bson Document representing the update to be applied to a matching document.

    completion

    The result of the attempt to update a document.

  • Updates a single document in a collection based on a query filter and returns the document in either its pre-update or post-update form. Unlike updateOneDocument, this action allows you to atomically find, update, and return a document with the same command. This avoids the risk of other update operations changing the document between separate find and update operations.

    Declaration

    Objective-C

    - (void)findOneAndUpdateWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                   updateDocument:(nonnull NSDictionary<NSString *, id<RLMBSON>> *)
                                      updateDocument
                          options:(nonnull RLMFindOneAndModifyOptions *)options
                       completion:(nonnull RLMMongoFindOneBlock)completion;

    Parameters

    filterDocument

    A bson Document representing the match criteria.

    updateDocument

    A bson Document representing the update to be applied to a matching document.

    options

    RemoteFindOneAndModifyOptions to use when executing the command.

    completion

    The result of the attempt to update a document.

  • Updates a single document in a collection based on a query filter and returns the document in either its pre-update or post-update form. Unlike updateOneDocument, this action allows you to atomically find, update, and return a document with the same command. This avoids the risk of other update operations changing the document between separate find and update operations.

    Declaration

    Objective-C

    - (void)findOneAndUpdateWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                   updateDocument:(nonnull NSDictionary<NSString *, id<RLMBSON>> *)
                                      updateDocument
                       completion:(nonnull RLMMongoFindOneBlock)completion;

    Parameters

    filterDocument

    A bson Document representing the match criteria.

    updateDocument

    A bson Document representing the update to be applied to a matching document.

    completion

    The result of the attempt to update a document.

  • Overwrites a single document in a collection based on a query filter and returns the document in either its pre-replacement or post-replacement form. Unlike updateOneDocument, this action allows you to atomically find, replace, and return a document with the same command. This avoids the risk of other update operations changing the document between separate find and update operations.

    Declaration

    Objective-C

    - (void)findOneAndReplaceWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
               replacementDocument:(nonnull NSDictionary<NSString *, id<RLMBSON>> *)
                                       replacementDocument
                           options:(nonnull RLMFindOneAndModifyOptions *)options
                        completion:(nonnull RLMMongoFindOneBlock)completion;

    Parameters

    filterDocument

    A Document that should match the query.

    replacementDocument

    A Document describing the replacement.

    options

    RLMFindOneAndModifyOptions to use when executing the command.

    completion

    The result of the attempt to replace a document.

  • Overwrites a single document in a collection based on a query filter and returns the document in either its pre-replacement or post-replacement form. Unlike updateOneDocument, this action allows you to atomically find, replace, and return a document with the same command. This avoids the risk of other update operations changing the document between separate find and update operations.

    Declaration

    Objective-C

    - (void)findOneAndReplaceWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
               replacementDocument:(nonnull NSDictionary<NSString *, id<RLMBSON>> *)
                                       replacementDocument
                        completion:(nonnull RLMMongoFindOneBlock)completion;

    Parameters

    filterDocument

    A Document that should match the query.

    replacementDocument

    A Document describing the update.

    completion

    The result of the attempt to replace a document.

  • Removes a single document from a collection based on a query filter and returns a document with the same form as the document immediately before it was deleted. Unlike deleteOneDocument, this action allows you to atomically find and delete a document with the same command. This avoids the risk of other update operations changing the document between separate find and delete operations.

    Declaration

    Objective-C

    - (void)findOneAndDeleteWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                          options:(nonnull RLMFindOneAndModifyOptions *)options
                       completion:(nonnull RLMMongoDeleteBlock)completion;

    Parameters

    filterDocument

    A Document that should match the query.

    options

    RLMFindOneAndModifyOptions to use when executing the command.

    completion

    The result of the attempt to delete a document.

  • Removes a single document from a collection based on a query filter and returns a document with the same form as the document immediately before it was deleted. Unlike deleteOneDocument, this action allows you to atomically find and delete a document with the same command. This avoids the risk of other update operations changing the document between separate find and delete operations.

    Declaration

    Objective-C

    - (void)findOneAndDeleteWhere:
                (nonnull NSDictionary<NSString *, id<RLMBSON>> *)filterDocument
                       completion:(nonnull RLMMongoDeleteBlock)completion;

    Parameters

    filterDocument

    A Document that should match the query.

    completion

    The result of the attempt to delete a document.

  • Opens a MongoDB change stream against the collection to watch for changes. The resulting stream will be notified of all events on this collection that the active user is authorized to see based on the configured MongoDB rules.

    Declaration

    Objective-C

    - (nonnull RLMChangeStream *)watchWithDelegate:
                                     (nonnull id<RLMChangeEventDelegate>)delegate
                                     delegateQueue:(nullable dispatch_queue_t)queue;

    Parameters

    delegate

    The delegate that will react to events and errors from the resulting change stream.

    queue

    Dispatches streaming events to an optional queue, if no queue is provided the main queue is used

  • Opens a MongoDB change stream against the collection to watch for changes made to specific documents. The documents to watch must be explicitly specified by their _id.

    Declaration

    Objective-C

    - (nonnull RLMChangeStream *)
        watchWithFilterIds:(nonnull NSArray<RLMObjectId *> *)filterIds
                  delegate:(nonnull id<RLMChangeEventDelegate>)delegate
             delegateQueue:(nullable dispatch_queue_t)queue;

    Parameters

    filterIds

    The list of _ids in the collection to watch.

    delegate

    The delegate that will react to events and errors from the resulting change stream.

    queue

    Dispatches streaming events to an optional queue, if no queue is provided the main queue is used

  • Opens a MongoDB change stream against the collection to watch for changes. The provided BSON document will be used as a match expression filter on the change events coming from the stream.

    See https://docs.mongodb.com/manual/reference/operator/aggregation/match/ for documentation around how to define a match filter.

    Defining the match expression to filter ChangeEvents is similar to defining the match expression for triggers: https://docs.mongodb.com/realm/triggers/database-triggers/

    Declaration

    Objective-C

    - (nonnull RLMChangeStream *)
        watchWithMatchFilter:
            (nonnull NSDictionary<NSString *, id<RLMBSON>> *)matchFilter
                    delegate:(nonnull id<RLMChangeEventDelegate>)delegate
               delegateQueue:(nullable dispatch_queue_t)queue;

    Parameters

    matchFilter

    The $match filter to apply to incoming change events

    delegate

    The delegate that will react to events and errors from the resulting change stream.

    queue

    Dispatches streaming events to an optional queue, if no queue is provided the main queue is used