Class RemoteUpdateResult

  • Direct Known Subclasses:
    SyncUpdateResult

    public class RemoteUpdateResult
    extends Object
    The result of an update operation.
    • Example

      Document filterDoc = new Document().append("name", "legos");
      Document updateDoc = new Document().append("$set",
          new Document()
          .append("name", "blocks")
          .append("price", 20.99)
          .append("category", "toys")
      );
      
      final Task<RemoteUpdateResult> updateTask =
          itemsCollection.updateOne(filterDoc, updateDoc);
      updateTask.addOnCompleteListener(new OnCompleteListener <RemoteUpdateResult> () {
          @Override
          public void onComplete(@NonNull Task <RemoteUpdateResult> task) {
              if (task.isSuccessful()) {
                  long numMatched = task.getResult().getMatchedCount();
                  long numModified = task.getResult().getModifiedCount();
                  Log.d("app", String.format("successfully matched %d and modified %d documents",
                          numMatched, numModified));
              } else {
                  Log.e("app", "failed to update document with: ", task.getException());
              }
          }
      });
      
    • Constructor Detail

      • RemoteUpdateResult

        public RemoteUpdateResult​(long matchedCount,
                                  long modifiedCount,
                                  BsonValue upsertedId)
        Constructs a result.
        Parameters:
        matchedCount - the number of documents matched by the query.
        modifiedCount - the number of documents modified.
        upsertedId - the _id of the inserted document if the replace resulted in an inserted document, otherwise null.
    • Method Detail

      • getMatchedCount

        public long getMatchedCount()
        Returns the number of documents matched by the query.
        Returns:
        the number of documents matched.
      • getModifiedCount

        public long getModifiedCount()
        Returns the number of documents modified.
        Returns:
        the number of documents modified.
      • getUpsertedId

        @Nullable
        public BsonValue getUpsertedId()
        If the replace resulted in an inserted document, gets the _id of the inserted document, otherwise null.
        Returns:
        if the replace resulted in an inserted document, the _id of the inserted document, otherwise null.