I want to move a specific doc with all his nested collections from one collection to another.
is it possible?
db.collection('codes).doc(specificDoc).setLocation(db.collection('archive))
or somthing like this
Asked
Active
Viewed 1,425 times
2

Renaud Tarnec
- 79,263
- 10
- 95
- 121

itay
- 43
- 6
-
If you understand Java, you can also take a look at my answer from this post: [How to move a document in Cloud Firestore](https://stackoverflow.com/questions/47244403/how-to-move-a-document-in-cloud-firestore). – Alex Mamo Mar 22 '20 at 16:54
1 Answers
1
Firestore does not offer any way to move documents between collections. What you will need to do instead is query for the documents to move, iterate them, write new documents in the archive collection, and delete the original.
Consider instead just using a field in each document to mark whether or not it is archived, and use that field to filter the results.

Doug Stevenson
- 297,357
- 32
- 422
- 441
-
I would add that you need to do the same for each subcollection (i.e. "nested collection") of each document you move, since queries are shallow in Firestore. – Renaud Tarnec Mar 22 '20 at 16:34
-
I would add to use cloud functions if there is a need of moving this data each day or at a specific time, also when the functions is triggered – Gastón Saillén Mar 22 '20 at 16:39