1

Is it possible to observe only a particular set of data that my iOS app writes to a Firebase database?

To elaborate at a high level :
I have a database in Firebase that stores some data per user (name, email, didCompleteCourse).
This data (for each user) is written to Firebase by my iOS app.
At a later date, a server side script updates 'didCompleteCourse' for each user based on some data gathered elsewhere. Basically, it kind of toggles a flag for that property in each user record.

Now, I want to be notified via observing when this flag is changed for only that/those users(in case multiple users login into my app on a particular device) whose data was sent to firebase through my iOS app from a particular device.

Any kind of code will help.

6
  • Basically you want to observe a particular node in your Firebase Database? Commented Oct 25, 2016 at 12:19
  • Can you provide some information about how the database is structured? Not just the structure of the user data, but also the structure of the path leading to it. (For example, is each user stored against a userid?) Commented Oct 25, 2016 at 12:19
  • @Dravidian : Several such nodes Commented Oct 25, 2016 at 12:22
  • @Prisoner: Its a flat structure with root node 'Users'. Then there are 3 child nodes 'iOS', 'Android' & 'Windows'. Each of these child nodes will contain an array of 'User' where each user has properties such as name, email and a boolean called courseCompletion. Commented Oct 25, 2016 at 12:31
  • Note that I'm wary of the entire snapshot of data being retrieved which is what I would like to avoid directly by a query or some other mechanism available. Commented Oct 25, 2016 at 12:32

1 Answer 1

1

Try using:-

 FIRDatabase.database().reference().child("_yourRef").observe(.childChanged, with: { (SnapShot) in print(SnapShot.value) }, withCancel: {(Error) in print(Error.localizedDescription) }) 

This will Create a separate network thread in your users App, and whenever your DB nodes will change its value your this completionBlock will get fired and the retrieved data will only be of the child node changed not the entire node consuming your Bandwidth.

FIRDataEventType's:-

  • childAdded : fired when a new child node is added to a location

  • childRemoved : fired when a child node is removed from a location

  • childChanged : fired when a child node at a location changes

  • childMoved : fired when a child node moves relative to the other child nodes at a location

  • value : fired when any data changes at a location and, recursively, any children

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.