For the JSON structure: -
"posts" : { "autoID1" : { "key" : "autoID1", "timestamp" : 101 }, "autoID2" : { "key" : "autoID2", "timestamp" : 102 }, "autoID3" : { "key" : "autoID3", "timestamp" : 103 }, "autoID4" : { "key" : "autoID4", "timestamp" : 104 }, "autoID5" : { "key" : "autoID5", "timestamp" : 105 }, "autoID6" : { "key" : "autoID6", "timestamp" : 106 }, "autoID7" : { "key" : "autoID7", "timestamp" : 107 } }
Use this code: -
FIRDatabase.database().reference().child("posts").queryOrderedByChild( "timestamp").queryStartingAtValue(101).queryEndingAtValue(103).observeEvenType(.Value, with: { (snap) in if let snapDict = snap.value as? [String:AnyObject]{ for each in snapDict{ print(each.value) } } }, withCancel: {(err) in })
Make sure your security rules allow the user to retrieve posts value
Using .ChildAdded only called when a child node is added to this node database. Using .Value , you get integer data whose timestamp is between these values
Now, most likely, you cannot get the Timestamp value from FIRServerValue.timestamp() , as this is just a command sent to the firebase server to add a label to this especially node.
Instead, use a custom timestamp to save the timestamp, and for the final value, simply add 15 minutes to this timestamp.
Read This Manipulate NSDate