Q:

Search/Fetch objects on a firebase real time database

I have a realtime database on Firebase that has something like:

Pets
  
  
UNIQUE_ID
  
  
name: Beethoven
breed: Labrador,Golden
category: Adoption, Temporally-adoption
age: ...
...

Since I'm new on Firebase, I have few doubts on how to use Firebase database  that I couldn't get a clue on their documentation, can you help me?

I'm trying to create a Cloud Function (to be used as a REST API) where I could search across all pets from a particular category, for example, Adoption. Is that possible? I can create, update... but I don't see how I should do this search... 

var ref = admin.database().ref('/pets');
ref.????

Can I create something similar as pagination from Cloud Functions against this search?
I'm not familiar with this type of NoSQL databases, but do I need to create an index to do those objects searchable? I'm completely lost here, too. :(
It is weird to use this Cloud functions to do this type of searches? Or should I use their own SDKs per each platform? Do they provide this searches too? Looks to me that it is easier to create a Cloud functions and call it from any platform as a rest call, right?

Thanks!

A:

Yes, this is possible, and if your goal is to create an API then you will need to use Cloud Functions for this. I would recommend that you switch from Firebase's realtime database to firestore. The realtime database is older and lacks some of the rich queries, the Firestore database has better support for advanced queries... 
Yep, check out these Firestore docs for examples of pagination.
Not unless you get a huge data set, as a beginner, I'd recommend you not worry about indexing.
You can do it either way, but if you're looking for cross-platform, then you're right - creating an API like this could definitely save you some trouble down the road.

