Where in strings list does not work Cloud Firestore

0

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

Below is the code 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 can I be doing wrong?

    
asked by anonymous 19.07.2018 / 17:40

1 answer

1

As you are in the Firebase documentation , using the data so does not allow 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
    }
}

Notice 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()))
    
19.07.2018 / 17:50