I am using the v9 Web SDK.
I have a collection called 'transactions-in' which keeps a record of every transaction into a cardano wallet.
From time to time my server will send a transaction in response to each transaction in this collection (such as sending an nft or refunding ADA) and I want to add these transactions into a subcollection on the relevant transaction document, so the structure looks like this:
- collection: 'payments_in'
- document: document ID
- subcollection: 'related_transactions'
- document: newly created document reference
This is the code I have to get the right path to the newly created document ref and upload some test data into the firebase emulator:
//1. Get current doc
const currentDoc = doc(db, 'payments_in', transactionId);
//2. Build refund database entry
//2A. Get collection from database (will create one if doesn't exist)
const newCollection = collection(currentDoc, 'related_transactions');
//2B. Get a new document from database within new collection
const newSubDoc = doc(newCollection);
//2C. Upload entry to database
await setDoc(newSubDoc, { test: 'test' });
When I log the path of newSubDoc I get this, so the path looks good (I think??): payments_in/kXK5pimm29nRhU4CohA6/related_transactions/NL11eYmsB4M9vHw6PI8X
However when I try to submit the entry using setDoc I get the following error message:
@firebase/firestore: Firestore (9.1.1): Connection GRPC stream error.
Code: 3 Message: 3 INVALID_ARGUMENT: Document name "projects//databases/(default)/documents/payments_in/kXK5pimm29nRhU4CohA6/related_transactions/tLoCiHUJaA2uYhxt7drb"
lacks a project id at index 9.
Does anyone see what I am doing wrong here?
Thanks
CodePudding user response:
If you look at the path in the error message, it is missing a project ID after projects/
: projects//databases/(default)/documents/payments_in/kXK5pimm29nRhU4CohA6/related_transactions/tLoCiHUJaA2uYhxt7drb
. You might want to double check how you initialize db
and whether your Firebase configuration is complete.