Realm.RemoteMongoDBCollection

A remote collection of documents in a MongoDB database.

aggregate(pipeline)Promise<[object>, ...]
async

Runs an aggregation framework pipeline against this collection.

Parameters:
  • pipeline
    • Type: [object, ...]
    • An array of aggregation pipeline stages.

Returns: Promise<[object>, ...] The result.
count(filter, options)Promise<number>
async

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

Parameters:
  • filter optional
    • Type: object
    • An optional filter applied to narrow down the results.

  • options optional
    • Type: object
    • Additional options to apply.

      • limit optional
        • Type: number
        • The maximum number of documents to return.

Returns: Promise<number>
deleteMany(filter)Promise<DeleteResult>
async

Deletes multiple documents.

Parameters:
  • filter
    • Type: object
    • A filter applied to narrow down the result.

Returns: Promise<DeleteResult>
deleteOne(filter)Promise<DeleteResult>
async

Deletes a single matching document from the collection.

Parameters:
  • filter
    • Type: object
    • A filter applied to narrow down the result.

Returns: Promise<DeleteResult>
find(filter, options)Promise<[object>, ...]
async

Finds the documents which match the provided query.

Parameters:
  • filter optional
    • Type: object
    • An optional filter applied to narrow down the results.

  • options optional
    • Type: object
    • Additional options to apply.

      • sort optional
        • Type: object
        • The order in which to return matching documents.

      • limit optional
        • Type: number
        • The maximum number of documents to return.

Returns: Promise<[object>, ...] The documents.
findOne(filter, options)Promise<object>
async

Finds a document which matches the provided filter.

Parameters:
  • filter optional
    • Type: object
    • An optional filter applied to narrow down the results.

  • options optional
    • Type: object
    • Additional options to apply.

      • sort optional
        • Type: object
        • The order in which to return matching documents.

Returns: Promise<object> The document or null if nothing matched.
findOneAndDelete(filter, options)Promise<object>
async

Finds a document which matches the provided filter and deletes it

Parameters:
  • filter
    • Type: object
    • A filter applied to narrow down the results.

  • options optional
    • Type: object
    • Additional options to apply.

      • sort optional
        • Type: object
        • The order in which to return matching documents.

Returns: Promise<object> The document or null if nothing matched.
findOneAndReplace(filter, replacement, options)Promise<?object>
async

Finds a document which matches the provided filter and replaces it with a new document.

Parameters:
  • filter
    • Type: object
    • A filter applied to narrow down the results.

  • replacement
    • Type: object
    • The new values for the document.

  • options optional
    • Type: object
    • Additional options to apply.

      • sort optional
        • Type: object
        • The order in which to return matching documents.

      • upsert optional
        • Type: boolean
        • Default: false
        • if true, indicates that MongoDB should insert a new document that matches the query filter when the query does not match any existing documents in the collection.

      • returnNewDocument optional
        • Type: boolean
        • Default: false
        • if true, indicates that the action should return the document in its updated form instead of its original, pre-update form.

Returns: Promise<?object> The document (before or after modification) or null if nothing matched.
findOneAndUpdate(filter, update, options)Promise<?object>
async

Finds a document which matches the provided query and performs the desired update to individual fields.

Parameters:
  • filter
    • Type: object
    • A filter applied to narrow down the results.

  • update
    • Type: object
    • The new values for the document.

  • options optional
    • Type: object
    • Additional options to apply.

      • sort optional
        • Type: object
        • The order in which to return matching documents.

      • upsert optional
        • Type: boolean
        • Default: false
        • if true, indicates that MongoDB should insert a new document that matches the query filter when the query does not match any existing documents in the collection.

      • returnNewDocument optional
        • Type: boolean
        • Default: false
        • if true, indicates that the action should return the document in its updated form instead of its original, pre-update form.

Returns: Promise<?object> The document (before or after modification) or null if nothing matched.
insertMany(documents)Promise<InsertManyResult>
async

Inserts an array of documents into the collection. If any values are missing identifiers, they will be generated by the server.

Parameters:
  • documents
    • Type: [object, ...]
    • The array of documents.

Returns: Promise<InsertManyResult> The _ids of the inserted documents.
insertOne(document)Promise<InsertOneResult>
async

Inserts a single document into the collection. Note: If the document is missing an _id, one will be generated for it by the server.

Parameters:
  • document
    • Type: object
    • The document.

Returns: Promise<InsertOneResult> The _id of the inserted document.
updateMany(filter, update, options)Promise<UpdateResult>
async

Updates multiple documents matching the provided filter in this collection.

Parameters:
  • filter
    • Type: object
    • A filter applied to narrow down the results.

  • update
    • Type: object
    • The new values for the document.

  • options optional
    • Type: object
    • Additional options to apply.

      • upsert optional
        • Type: boolean
        • Default: false
        • if true, indicates that MongoDB should insert a new document that matches the query filter when the query does not match any existing documents in the collection.

Returns: Promise<UpdateResult>
updateOne(filter, update, options)Promise<UpdateResult>
async

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

Parameters:
  • filter
    • Type: object
    • A filter applied to narrow down the results.

  • update
    • Type: object
    • The new values for the document.

  • options optional
    • Type: object
    • Additional options to apply.

      • upsert optional
        • Type: boolean
        • Default: false
        • if true, indicates that MongoDB should insert a new document that matches the query filter when the query does not match any existing documents in the collection.

Returns: Promise<UpdateResult>
watch(options)ChangeEvent
asyncgenerator

Creates an asynchronous change stream to monitor this collection for changes.

By default, yields all change events for this collection. You may specify at most one of the filter or ids options.

Parameters:
  • options optional
    • Type: object
    • Default: {}
      • filter optional
        • Type: object
        • A filter for which change events you are interested in.

      • ids optional
        • Type: [any, ...]
        • A list of ids that you are interested in watching

ChangeEvent

An event in a change stream.

Note that which properties are present will depend on both the operationType field, which is itself always present, and the MongoDB server version.

Type:
object
Properties:
  • _id
    • The opaque resume token for this event.

  • operationType
    • Type: string
    • What kind of operation was this? One of: "insert", "delete", "replace", "update", "drop", "rename", "dropDatabase", or "invalidate".

  • fullDocument
    • Type: object
    • A full copy of the document that was touched by this operation. See the mongodb reference manual for details about which version of the document will be returned.

  • ns
    • Type: object
    • Namespace of the collection affected by this event.

      • db
        • Type: string
        • Database name

      • coll
        • Type: string
        • Collection name

  • to
    • Type: object
    • Destination namespace for "rename" events.

      • db
        • Type: string
        • Database name

      • coll
        • Type: string
        • Collection name

  • documentKey
    • Type: object
    • The _id and shard key of the modified document. _id is not duplicated if it is part of the shard key.

  • updateDescription
    • Type: object
      • updatedFields
        • Type: object
        • An object mapping from modified field names to their new values.

      • removedFields
        • Type: [string, ...]
        • A list of field names that were removed.

  • clusterTime
    • Type: Timestamp
    • The timestamp from the oplog entry associated with the event.

  • txnNumber
    • Type: Long
    • The transaction number. Only present if part of a multi-document transaction.

  • lsid
    • Type: object
    • The logical session id of the transaction. Only present if part of a multi-document transaction.

DeleteResult

Result of deleting documents

Type:
object
Properties:
  • deletedCount
    • Type: number
    • The number of documents that were deleted.

InsertManyResult
Properties:
  • insertedIds
    • Type: Array
    • The ids of the inserted documents

InsertOneResult
Properties:
  • insertedId
    • The id of the inserted document

UpdateResult

Result of updating documents

Type:
object
Properties:
  • matchedCount
    • Type: number
    • The number of documents that matched the filter.

  • modifedCount
    • Type: number
    • The number of documents matched by the query.

  • upsertedId optional
    • The identifier of the inserted document if an upsert took place.