0

I have data in Firestore as (Collection) Movies -> (Document) MovieId -> (Array).

Each movie document can have many arrays which are named in a date format MM-DD-YYYY. My question is, is there any way to query these arrays by their name? Considering the name is current date.

For example if I want to run a cloud function that gives me all the today's date array from all the movies?

Something like below...

var moviesRef = db.collection('movies');
var query = moviesRef.where("01-16-2019", "==", "01-16-2019");

The 01-16-2019 is my array name.

enter image description here

Thanks in advance

1 Answer 1

2

You can't do this the way your data is structured. Array type fields can only be queried by their entire contents for equality (whole list to whole list comparison), or for a single element in the array by its exact value using array-contains.

You can't query a document based on the mere existence of a field either.

If you want to query these documents by some date, you will need to add those dates as the members of an array or a fields of an object whose values map to something like 'true'.

Sign up to request clarification or add additional context in comments.

3 Comments

Ohh, it means either I need to change my data structure or need to loop through each and every movie and check whether array with today's date name exists or not :-(
Either change your data, or duplicate data. Data duplication is common in nosql type databases in order to help satisfy specific kinds of queries.
Changing data is a better option instead of scanning each and every movie and check each and every array name with today's date is not a good Idea. I will move the date to the collection and movie id will be the children of the collection with other values. It will look like below. var dateRef = db.collection('01-16-2019'); var docs = dateRef.getDocuments(); Thanks for you time and help @Doug Stevenson

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.