Let me explain the structure of my data:
Each element
contains a cluster
object, and the cluster
object includes a tags
object with one or more tag
objects.
This setup aligns with firebase's denormalized data structure, as outlined here. We implement multi-path updates and lookup tables to maintain data consistency, which is why tags
cannot be an array!
I want to query based on the document ids within the nested tags
object.
I am aware that firestore.FieldPath.documentId()
retrieves the document id and can be utilized in a query like this:
db.collection('elements').where(firestore.FieldPath.documentId(), 'in', ["a element document id"]).get().then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
However, I aim to use it within a nested object like this:
db.collection('elements').where('cluster.tags.'+firestore.FieldPath.documentId(), 'in', ["a element document id"]).get().then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
I did not anticipate my approach to work as expected, and I have not come across any examples of this. Although elements.cluster.tags
serves as a valid FieldPath
, how can I access the documentId()
within a .where()
query?
Any suggestions?