0

Based on Tom's answer to this question, I'm getting the following error when trying to query a nested field on a collection.

I'm trying to get a single user object with personalityExams.id.extId = 24232. I'd like to know the best way to query this, and how to form an index rule for it.

Here is what the user looks like in firebase

{
  "users": {
    "93306b91-d5ba-4e06-838c-0ab85fd58783": {
      "createdOn" : 1451495976870,
      "email" : "iyad.bitar@gmail.com",
      "firstName" : "Iyad",
      "lastModifiedOn" : 1451590413654,
      "lastName" : "Bitar",
      "mobile" : "34234333",
      "provider" : "password",
      "userType" : "JS",
      "personalityExams": [
        {
          "extId": "24232",
          "skills": ["teaching"]
        }
      ]
}

In my javascript, I'm trying to get it like so:

(new Firebase("https://hirely-dev.firebaseio.com/users")).orderByValue("personalityExams/extId").equalTo("24232").on("value", function(snapshot) {user1 = snapshot.val();});

Error:

Uncaught Error: Query.orderByValue failed: Was called with 1 argument. Expects none.
    at Error (native)
    at x (http://localhost:7200/lib/firebase/firebase.js:20:1074)
    at U.g.Fg (http://localhost:7200/lib/firebase/firebase.js:233:343)
    at <anonymous>:2:59
    at Object.InjectedScript._evaluateOn (<anonymous>:875:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:808:34)
    at Object.InjectedScript.evaluate (<anonymous>:664:21)
Community
  • 1
  • 1
bdombro
  • 1,251
  • 11
  • 17
  • 1
    I think you mean to be using `orderByChild`. Regardless, if `personalityExams` is an array (or list), this wouldn't work because `orderByChild` would order users by the exact given path. – Anid Monsur Jan 01 '16 at 20:15
  • Sounds like an answer @AnidMonsur ! :-) – Frank van Puffelen Jan 02 '16 at 01:32
  • Thanks for the responses. I don't actually mean orderByChild, because that function does not accept nesting like "personalyExams/extId". I heard that Firebase was going to start supporting this? I do understand though that it being an array may make the query impossible though. With all do respect though, I don't consider this answered because nobody has told me it's impossible or how to solve it :0/ – bdombro Jan 02 '16 at 17:24
  • 1
    You'll need an inverse index for that lookup. See http://stackoverflow.com/questions/27207059/firebase-query-double-nested – Frank van Puffelen Jan 02 '16 at 23:41
  • Thanks, Frank. I think you are right. – bdombro Jan 05 '16 at 02:36

0 Answers0