firebase-admin-node: FieldPath.documentId() must be a string or a DocumentReference

  • Operating System version: macOS Catalina
  • firebase-admin version 8.12.1
  • Firebase Product: firestore
  • Node.js version: 10

Problem

This query doesn’t work when using firebase-admin, throwing an error:

‘… FieldPath.documentId() must be a string or a DocumentReference’

import admin from 'firebase-admin'

const menus = await admin
  .firestore()
  .collection('menus')
  .where(admin.firestore.FieldPath.documentId(), 'in', [
    'cUKi4Kj42LOcLsqBZOBhM',
  ])
  .get()

This issue has been reported and apparently resolved in nodejs-firestore (https://github.com/googleapis/nodejs-firestore/issues/990)

Same query using the @google-cloud/firestore package works:

import { FieldPath, Firestore } from '@google-cloud/firestore'

const firestore = new Firestore()

const menus = await firestore
  .collection('menus')
  .where(FieldPath.documentId(), 'in', ['cUKi4Kj42LOcLsqBZOBhM'])
  .get()

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (9 by maintainers)

Most upvoted comments

Still having this issue, using both @google/cloud-firestore and firebase-admin throwing this error: Error: The corresponding value for FieldPath.documentId() must be a string or a DocumentReference, but was "1"

package.json: "dependencies": { "@firebase/testing": "^0.20.9", "@google-cloud/firestore": "^4.1.1", "@types/cors": "^2.8.6", "body-parser": "^1.19.0", "cors": "^2.8.5", "express": "^4.17.1", "firebase-admin": "^9.0.0", "firebase-functions": "^3.6.1", "firebase-tools": "^8.6.0", "nodemon": "^2.0.4" },

I tried uninstalling, installing both dependencies, deleting node_modules and installing everything all over again, no luck.

Also running using local emulator.

It doesn’t reproduce to us. It also seems other developers managed to get it working by simply reinstalling the dependencies. We will need some sort of a test app to repro this. If you can provide a simplified version of your project that would be most helpful.

I needed to remove and recreate the lock file to get the latest version of @google-cloud/firestore. It all works now.