I have a database in a GCP project "A" that was created from a copy of another database in project "B". This was achieved with the Cloud Firestore managed export and import service from GCP.
When trying to load documents from a specific collection from the database in project "A", an error is raised:
ValueError Traceback (most recent call last)
<ipython-input-16-935f61174138> in <module>()
1 collection_docs = db.collection("<collection>").stream()
----> 2 for doc in collection_docs:
3 print(doc.id)
5 frames
/usr/local/lib/python3.7/dist-packages/google/cloud/firestore_v1/_helpers.py in reference_value_to_document(reference_value, client)
245 if document._document_path != reference_value:
246 msg = WRONG_APP_REFERENCE.format(reference_value, client._database_string)
--> 247 raise ValueError(msg)
248
249 return document
ValueError: Document 'projects/<project B>/databases/(default)/documents/<another collection>/<document>' does not correspond to the same database ('projects/<project A>/databases/(default)') as the client.
Note that <another collection> is referenced in documents from <collection>
Why the reference keeps pointing to the old database?
UPDATE: It turns out the initial export was correct and the references properly updated, but after that, while updating other fields using a buggy Python script, the references got unnecessarily and incorrectly "updated" to the old project.
The correct way to obtain this field would be:
db.document(<document reference>.path)
Still this question remains:
Is it possible to load the documents without bringing the reference?
Here is the Python snippet that produces the error:
cred = credentials.ApplicationDefault()
firebase_admin.initialize_app(cred, {
'projectId': <project A>,
})
db = firestore.client()
collection_docs = db.collection("<collection>").stream()
for doc in collection_docs:
print(doc.id)