question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FieldPath.documentId() must be a string or a DocumentReference

See original GitHub issue
  • 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()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
13dante04commented, Jul 25, 2020

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.

1reaction
hiranya911commented, Jun 25, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firestore query where(documentId(), 'in', array) is giving me ...
Error: The corresponding value for FieldPath.documentId() must be a string or a DocumentReference. Here is my code: const admin = require(' ...
Read more >
FieldPath | JavaScript SDK | Firebase JavaScript API reference
A FieldPath refers to a field in a document. The path may consist of a single field name (referring to a top-level field...
Read more >
com.google.cloud.firestore.FieldPath.documentId java ...
documentId() must be a String or a " + "DocumentReference.", e.getMessage()); } try { query.orderBy(FieldPath.documentId()).startAt("coll/doc/coll").get(); ...
Read more >
Node / Firestore query on auto-ID returns "no documents ...
I have identified a BUG in match FieldPath.documentId(). It *only* matches to the *full path* of the document, NOT, the specific ID. A...
Read more >
Uses of Class com.google.cloud.firestore.FieldPath
documentId(). A special sentinel to refer to the ID of a document. static FieldPath, FieldPath. of(String... fieldNames). Creates a FieldPath from the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found