Stack Overflow Asked by thurahtetaung on February 18, 2021
I am trying to sort a document stored in Firestore by a field of integers, but while trying to do so, I got this error. type Query is not a subtype of type Collection Reference
My code is
final CollectionReference timetableCollection = Firestore.instance.collection('timetables').orderBy('Period');
where period only contain integers.The code works fine if I don’t do the orderBy part.
I looked at the documentation and it says CollectionReference extends on Query so I don’t understand where to fix.
I'm sure you can see from the API documentation that collection()
returns a CollectionReference, and orderBy()
returns a Query.
It's true that CollectionReference is a subclass of Query. However, that doesn't mean that all Query objects are also CollectionReference objects. It means that all CollectionReference objects are also Query objects.
If you want to use a common data type, use Query. These lines of code should both compile:
final Query timetableQuery = Firestore.instance.collection('timetables');
final Query timetableOrderedQuery = Firestore.instance.collection('timetables').orderBy('Period');
Correct answer by Doug Stevenson on February 18, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP