const firebase = require("firebase");
// Required for side-effects
require("firebase/firestore");
// Initialize Cloud Firestore through Firebase
firebase.initializeApp({
apiKey: "____",
authDomain: "____",
projectId: "____"
});
var db = firebase.firestore();
var datasetSymptom=[{
"Disease" : [ "edema pulmonary" ],
"Symptom" : "Heberden's node"
}, {
"Disease" : [ "cholecystitis" ],
"Symptom" : "Murphy's sign"
}, {
"Disease" : [ "hemiparesis", "hypertension pulmonary", "transient ischemic attack" ],
"Symptom" : "Stahli's line"
}
]
datasetSymptom.forEach(function(obj) {
db.collection("datasetSymptom").doc(obj.Symptom).set({
Disease: obj.Disease
})
});
I already ran the same algo on another collection with same Disease
name as doc and array of symptoms as field. It worked fine.
Error:
D:
eact tutorial
eactnativefyp
ode_modules@firebasefirestoredist
ode-cjsdatabase-21da52c3-e2da0fdd.js:25868
throw replaceFunctionName(e, 'doc()', 'CollectionReference.doc()');
^
Error [FirebaseError]: Invalid document reference. Document references must have an even number of segments, but datasetSymptom/feels hot/feverish has 3.
at new FirestoreError (D:
eact tutorial
eactnativefyp
ode_modules←[4m@firebase←[24mfirestoredist
ode-cjsdatabase-21da52c3-e2da0fdd.js:209:28)
at validateDocumentPath (D:
eact tutorial
eactnativefyp
ode_modules←[4m@firebase←[24mfirestoredist
ode-cjsdatabase-21da52c3-e2da0fdd.js:19706:15)
at doc (D:
eact tutorial
eactnativefyp
ode_modules←[4m@firebase←[24mfirestoredist
ode-cjsdatabase-21da52c3-e2da0fdd.js:22462:9)
at CollectionReference$1.doc (D:
eact tutorial
eactnativefyp
ode_modules←[4m@firebase←[24mfirestoredist
ode-cjsdatabase-21da52c3-e2da0fdd.js:25864:64)
at D:
eact tutorial
eactnativefypindex2x2.js:1233:37
at Array.forEach (<anonymous>)
at Object.<anonymous> (D:
eact tutorial
eactnativefypindex2x2.js:1231:16)
←[90m at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:928:32)←[39m {
code: ←[32m'invalid-argument'←[39m,
toString: ←[36m[Function (anonymous)]←[39m
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
question from:
https://stackoverflow.com/questions/65859965/error-firebaseerror-invalid-document-reference-document-references-must-have 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…