I have a method that returns a string that I know for sure points to a document. When using that string as follow:
const docRef = "users/uid/data/online"
const dbPath = db.doc(docRef)
console.log(dbPath.path)
return dbPath.set({"test" : 1})
It fails:
If I use db.collection("users").doc(uid)...... it works. How can I create a document reference through a string in typescript?
It should work according to the docs: https://firebase.google.com/docs/firestore/data-model#references
edit: This is my class:
export enum UserCollection {
online = "online",
private = "private",
server = "server"
}
export enum UserDocument {
online = "online",
private = "private",
server = "server"
}
class ManagerPath {
pathToUser = "users/"
getPathToUser(uid: string, userCollection: UserCollection, userDocument: UserDocument): string {
return this.pathToUser + "/" + uid + "/" + userCollection + "/" + userDocument;
}
}
export const managerPath = new ManagerPath();
And this is how I retrieve a path:
exports.initializeNewUser = functions.auth.user().onCreate((user) => {
const test = managerPath.getPathToUser(user.uid, UserCollection.online, UserDocument.online);
console.log(test)
const dbPath = db.doc(test)
return dbPath.set({"dateCreation" : Date.now()}) //fails
})
