RLMMongoCollection
Objective-C
@interface RLMMongoCollection : NSObject
Swift
@_nonSendable(_assumed) class RLMMongoCollection : NSObject, @unchecked Sendable
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:…];
See also
-
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
documentA
Documentvalue to insert.completionThe 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
documentsThe
Documentvalues in a bson array to insert.completionThe 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
filterDocumentA
Documentas bson that should match the query.optionsRLMFindOptionsto use when executing the command.completionThe 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
filterDocumentA
Documentas bson that should match the query.completionThe 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
filterDocumentA
Documentas bson that should match the query.optionsRLMFindOptionsto use when executing the command.completionThe 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
filterDocumentA
Documentas bson that should match the query.completionThe 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
pipelineA bson array made up of
Documentscontaining the pipeline of aggregation operations to perform.completionThe 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
filterDocumentA
Documentas bson that should match the query.limitThe max amount of documents to count
completionReturns 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
filterDocumentA
Documentas bson that should match the query.completionReturns 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
filterDocumentA
Documentas bson that should match the query.completionThe 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
filterDocumentDocument representing the match criteria
completionThe 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
filterDocumentA bson
Documentrepresenting the match criteria.updateDocumentA bson
Documentrepresenting the update to be applied to a matching document.upsertWhen true, creates a new document if no document matches the query.
completionThe 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
filterDocumentA bson
Documentrepresenting the match criteria.updateDocumentA bson
Documentrepresenting the update to be applied to a matching document.completionThe 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
filterDocumentA bson
Documentrepresenting the match criteria.updateDocumentA bson
Documentrepresenting the update to be applied to a matching document.upsertWhen true, creates a new document if no document matches the query.
completionThe 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
filterDocumentA bson
Documentrepresenting the match criteria.updateDocumentA bson
Documentrepresenting the update to be applied to a matching document.completionThe 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
filterDocumentA bson
Documentrepresenting the match criteria.updateDocumentA bson
Documentrepresenting the update to be applied to a matching document.optionsRemoteFindOneAndModifyOptionsto use when executing the command.completionThe 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
filterDocumentA bson
Documentrepresenting the match criteria.updateDocumentA bson
Documentrepresenting the update to be applied to a matching document.completionThe 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
filterDocumentA
Documentthat should match the query.replacementDocumentA
Documentdescribing the replacement.optionsRLMFindOneAndModifyOptionsto use when executing the command.completionThe 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
filterDocumentA
Documentthat should match the query.replacementDocumentA
Documentdescribing the update.completionThe 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
filterDocumentA
Documentthat should match the query.optionsRLMFindOneAndModifyOptionsto use when executing the command.completionThe 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
filterDocumentA
Documentthat should match the query.completionThe 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
delegateThe delegate that will react to events and errors from the resulting change stream.
queueDispatches 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
filterIdsThe list of _ids in the collection to watch.
delegateThe delegate that will react to events and errors from the resulting change stream.
queueDispatches 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
matchFilterThe $match filter to apply to incoming change events
delegateThe delegate that will react to events and errors from the resulting change stream.
queueDispatches streaming events to an optional queue, if no queue is provided the main queue is used
View on GitHub
Install in Dash