0

While using Angular Firestore we can use optional queries like this:

this.afs.collection(this.databaseCollection, ref => { return query ? query : ref; })

Is there something like this for the Admin SDK (firestore) as well? Or do I need to create a separate function for every query?

I would like to have one method (like above) where we can get all the documents in the collection if there is no query given, otherwise use the query.

  • so what's your problem? – SPatel Jan 04 '19 at 12:52
  • It says that I can only have one parameter for the collection method. But that means that for every action I have to have a method. I would like to have one method that does a call with a optional parameter. It says that the ref can not be used. – Mark van Turnhout Jan 04 '19 at 13:47

1 Answers1

0

If I understand you correctly you're trying to create a method that can take both a Query and a Collection as its argument.

In that case it helps to realize that the CollectionReference class extends the Query class. From the linked docs:

CollectionReference

CLASS

A CollectionReference object can be used for adding documents, getting document references, and querying for documents (using the methods inherited from Query).

Extends

Query

So if you create a method signature that accepts a Query, you can also pass a CollectionReference to it.

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807