I'm trying to query my firestore database to find all documents in a collection that include a certain object in an array field. So say my database has an articles collection like so:
articles:
[
{
id: "1",
title: "First Article",
comments:[]
relatedArticles:[
{
id: "2",
title:"Second Article"
},
{
id: "3",
title:"Third Article"
},
]
},
{
id: "2",
title: "Second Article",
comments:[]
relatedArticles:[
{
id: "1",
title:"First Article"
}
]
}
{
id: "3",
title: "Third Article",
comments:[]
relatedArticles:[
{
id: "1",
title:"First Article"
}
]
}
]
Every article in the articles collection has an array field (relatedArticles) which includes a set of objects each including both the id AND title of the related article. Say I wanted to query the database for all articles that have article 1 in their related articles field. How would I go about that assuming that this structure cannot be modified. I have tried the following to no avail:
firestore().collection("articles")
.where("relatedArticles", "array-contains", {title: "First Article", id: "1"})
Is this feasible? And if not, what is?