Realm.RemoteMongoDBCollection

A remote collection of documents in a MongoDB database.

aggregate(pipeline)[object, ...]
async

Runs an aggregation framework pipeline against this collection.

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

Returns: [object, ...] The result.
count(filter, options)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: number
deleteMany(filter)DeleteResult
async

Deletes multiple documents.

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

Returns: DeleteResult
deleteOne(filter)DeleteResult
async

Deletes a single matching document from the collection.

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

Returns: DeleteResult
find(filter, options)[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: [object, ...] The documents.
findOne(filter, options)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: object The document or null if nothing matched.
findOneAndDelete(filter, options)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: object The document or null if nothing matched.
findOneAndReplace(filter, replacement, options)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: object The document (before or after modification) or null if nothing matched. nullable
findOneAndUpdate(filter, update, options)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: object The document (before or after modification) or null if nothing matched. nullable
insertMany(documents)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: InsertManyResult The _ids of the inserted documents.
insertOne(document)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: InsertOneResult The _id of the inserted document.
updateMany(filter, update, options)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: UpdateResult
updateOne(filter, update, options)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: UpdateResult
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.