Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-70152

PeekableCursor's definition of hasNext() ignores the state of the stashed document

    • Fully Compatible
    • ALL
    • Sharding 2022-10-17

      PeekableCursor#hasNext() does not consider the state of this.stashedDoc. This causes the last document returned by the PeekableCursor to be considered missing by DataConsistencyChecker#getDiff() despite it potentially having the same _id as the cursor from the other cursor.

      class PeekableCursor {
          constructor(cursor) {
              this.cursor = cursor;
              this.stashedDoc = undefined;
          }
      
          hasNext() {
              return this.cursor.hasNext();
          }
      
          peekNext() {
              if (this.stashedDoc === undefined) {
                  this.stashedDoc = this.cursor.next();
              }
              return this.stashedDoc;
          }
      
          next() {
              const result = (this.stashedDoc === undefined) ? this.cursor.next() : this.stashedDoc;
              this.stashedDoc = undefined;
              return result;
          }
      }
      

            Assignee:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: