FieldPath.documentId() must be a string or a DocumentReference
See original GitHub issue- Operating System version: macOS Catalina
firebase-admin
version8.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:
- Created 3 years ago
- Comments:22 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.