
const subject_id = 3681; firestoreDb.collection('subject_data').doc(subject_id) .get().then(doc => {})しかし、そのままの状態で実行すると次のように怒られます。
(node:79393) UnhandledPromiseRejectionWarning: Error: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string. at Object.validateResourcePath (/Users/...../node_modules/@google-cloud/firestore/build/src/path.js:406:15) at CollectionReference.doc (/Users/...../node_modules/@google-cloud/firestore/build/src/reference.js:1982:20) at updateDataFromFirebase (/Users/...../test_updateDataFromFirebase.js:21:63) at Object.<anonymous> (/Users...../test_updateDataFromFirebase.js:16:1) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Function.Module.runMain (internal/modules/cjs/loader.js:831:12) (node:79393) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:79393) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.この場合、以下のようにNumberオブジェクト化して、toString化すると通ります。
const subject_id = new Number(3681).toString(); firestoreDb.collection('subject_data').doc(subject_id) .get().then(doc => {})参考:
https://firebase.google.com/docs/firestore/query-data/get-data?hl=ja#get_a_document
https://www.javadrive.jp/javascript/number_class/index2.html