4

I'm planning on fetching a list from my database, where certain records contain a property that may be set. I want to query and display items which don't have this property

{
  books: {
    book_3: {
     title: "Return of The King"
    },
    book_2: {
     title: "The Two Towers"
    },
    book_1: {
     title: "The Fellowship of the Ring"
     read: 1256953732
    }
  }
}

I've read the first book and I want to display the remaining two books. In Firebase I do:

fbl.child('books').orderByChild('read').equalTo(null).on("value", function(data) { 
 // handle data
}

And in AngularFire2 I would do something like:

this.af.database.list('books', { query: {
  orderByChild: 'read',
  equalTo: null
}});

The first way works and I get book_2, book_3, but the AngularFire2 way returns the whole list! Is there a value that can be indicated as a null value? I've tried booleans, empty strings etc. but nothing seems to work.

Perhaps this is a bug.

3
  • I had the same issue Commented Nov 29, 2016 at 14:57
  • It could be argued that it's a bug, as this is the test that's applied to the equalTo option. If null is a sensible value that's useful with the SDK, it should really only be ignoring undefined. I'd raise an issue. Commented Nov 29, 2016 at 22:32
  • @cartant issue raised: 704 Commented Nov 30, 2016 at 8:52

2 Answers 2

1

The problem has been fixed with this pull request - which was included in the 2.0.0-beta.7 release of AngularFire2.

The problem has been fixed with this pull request - which should be included in the published version of AngularFire2 that follows 2.0.0-beta.7.

With the fix, if you create queries like this:

this.af.database.list('books', { query: {
  orderByChild: 'read',
  equalTo: null
}});

They will behave as you would expect them to and will return only the list items that don't have read properties.

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

2 Comments

has there been any changes lately that breaks this. I'm getting full list again, not with null eleminiation.
"null elimination" is wrong term, but you get the problem.
0

You could just populate the "read" child of every node with 0 ( as you are storing the timestamp and its an integer value) and query something like this:

   af.database.list('books', { query: {
orderByChild: 'read', 
    equalTo: 0
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.