Skip to content
Advertisement

Is there a way to get all data from a firestore database using useCollectionData()?

I have a React project and in it I have the following code: (using this react hook for firebase)

const messagesRef = firestore.collection('messages');
const query = messagesRef.orederBy('createdAt').limit(25);
const [messages] = useCollectionData(query, {idField: 'id'});

Instead of this, I don’t want the query to be ordered or have a limit, is there a way to make an “empty” query to get all the data from a certain collection?

Advertisement

Answer

If you pass messagesRef instead of a query with orderBy() and limit() then the query should fetch all documents in the collection since a CollectionReference is a subclass of a Query:

const messagesRef = firestore.collection('messages');
const [messages] = useCollectionData(messagesRef, {idField: 'id'});
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement