I have this data structure, where todos are organized to follow path /todos/uid/
{
\"metausers\" : {
\"simplelogin:1\" : {
\"displayName\" : \"Jo
Assuming you have the uid, this should be straightforward with the following:
var uid = "simplelogin:1";
var todosRef = new Firebase("https://yourdb.firebaseio.com/todos/" + uid);
var privateTodosRef = todosRef.orderByChild("private").equalTo(true);
var privateTodos;
privateTodosRef.on("value", function(response) {
privateTodos = response.val();
});
This should return an object with all of this user's private todos, organized by their todo key (ie "-JUAfv4_-ZUlH7JqM4WZ"
. If you'd like to use Angularfire you can wrap this in a $firebaseArray and assign it as follows:
$scope.privateTodos = $firebaseArray(privateTodosRef);
Here's a reference for more info on complex queries, and as mentioned in the other responses there are some nice optimizations that can be done with priorities and restructuring.
Happy coding!
There are no WHERE
clauses in Firebase. Check out this thread for some great structural tips on searching by multiple fields, this thread on database style queries, this blog on queries, and the docs.
Your first approach should be to segment data how it will be read back. Something like the following:
/todos/public
/todos/private
/todos/completed
You can also utilize priorities as explained in the docs. Then fetch items based on priority.
If the list is less than a thousand, which it should be if data is properly partitioned, you can probably just grab the todo list and filter it at the client as well--a great option for short collections like this, particularly when working with a great binding lib like Angular.
All data in Firebaase can be accessed by URLs. If you go to your the Firebase dashboar to view your data model (Forge) and click on the property you are interested in you would be redirected to a URL by which you can access this particular data, e.g. https://myapp.firebaseio.com/todos/simplelogin:1/-JUAg9rVemiNQykfvvHs/private. Keeping this in mind you can access this data with AngularFire.