Where in string list does not work Cloud Firestore

Asked

Viewed 160 times

0

I am unable to return the documents from a collection where this document has a field called tags that is a list of strings with the tag ID.

Below follows the code of what I’m trying to do:

document = this.afs.collection('todos',
    ref => ref.where(tags, '==', 'ASOEOIN35O34N5O'));

The document fields are:

Document (all):

title: 'TITULO',
notes: 'NOTAS',
completed: true,
important: false,
tags: [{
 0: 'ASOEOIN35O34N5O',
 1: 'PWEPORJN2PNPGEW',
 3: 'POKAPASJPASFGGG'
}]

When performing a query with a query, nothing is returned.

What could I be doing wrong?

1 answer

1


How’s the Firebase documentation, Using the data like this doesn’t allow you to do what you want. They do, however, propose an alternative to make it work. You can structure your data as follows:

// Estrutura do documento na colecao
{
    title: "TITLE",
    note: "NOTE",
    completed: true,
    important: true,
    tags: {
         "ASOEOIN35O34N5O": true,
         "PWEPORJN2PNPGEW": true,
         "POKAPASJPASFGGG": true
    }
}

Note that in this case, instead of having an array, we have an object, where its attributes are the tags you want to use. Then just do the query, which from what I saw of your code, would become:

this.afs.collection('todos')
    .where('tags.ASOEOIN35O34N5O', '==', true)
    .get()
    .then(docs => docs.forEach(doc => console.log(doc.data()))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.