Skip to content

Firestore cursor methods not working with document snapshots #135

@myandrienko

Description

@myandrienko
  • Firebase SDK version: 5.5.0
  • Firebase Product: firestore

I'm using Firebase Admin SDK in Firebase Cloud Functions environment. I noticed that firebase.firestore.Query cursor methods, such as startAt, startAfter etc, are not working correctly when called with DocumentSnapshot as argument.

Collection test is populated with the following documents:

a: { v: "a", sort: 1 }
b: { v: "b", sort: 0 }
c: { v: "c", sort: 2 }

Here's my cloud function code:

const db = admin.firestore();
const coll = db.collection('test');
const query = coll.orderBy('sort');

return coll
  .doc('a')
  .get()
  .then((snap) =>
    query
      .startAt(snap)
      .get()
  )
  .then((snaps) => {
    console.log(snaps.size);
  });

Expected behavior to receive two documents (a and c), instead the following exception is thrown:

Error: Cannot encode type ([object Object]) to a Firestore Value
    at Function.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:669:11)
    at Query._buildPosition (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/reference.js:1267:44)
    at Query.startAt (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/reference.js:1295:28)
    at coll.doc.get.then (/user_code/index.js:20:8)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions