Multiple Indexes for collection - Only one works Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Catch multiple exceptions at once?firebase indexin method ? error in androidFirebase indexOn rules in unique keysFirebase Security Rules For A Node with Multiple ChildrenAdding and “.indexOn”: “.value” into Firebase RulesUsing an unspecified index. Consider adding “.indexOn”: “phone” at /use_frameworks_beta_2/searchIndex to your security rules for better performanceFirebase Index with Key as ParentIndex error in query in Firebaseunspecified index when searching data with firebase cloud function on nested object running nested QueryFirebase orderByChild with equalTo() doesn't work in javascript

Keep at all times, the minus sign above aligned with minus sign below

calculator's angle answer for trig ratios that can work in more than 1 quadrant on the unit circle

malloc in main() or malloc in another function: allocating memory for a struct and its members

Statistical analysis applied to methods coming out of Machine Learning

How do I say "this must not happen"?

Fit odd number of triplets in a measure?

Sally's older brother

Does the main washing effect of soap come from foam?

"Destructive power" carried by a B-52?

Is this Kuo-toa homebrew race balanced?

By what mechanism was the 2017 UK General Election called?

How to make triangles with rounded sides and corners? (squircle with 3 sides)

Can two people see the same photon?

Is this Half-dragon Quaggoth boss monster balanced?

First paper to introduce the "principal-agent problem"

Diophantine equation 3^a+1=3^b+5^c

Why not use the yoke to control yaw, as well as pitch and roll?

New Order #6: Easter Egg

Any stored/leased 737s that could substitute for grounded MAXs?

Is the time—manner—place ordering of adverbials an oversimplification?

Why do C and C++ allow the expression (int) + 4*5;

French equivalents of おしゃれは足元から (Every good outfit starts with the shoes)

Flight departed from the gate 5 min before scheduled departure time. Refund options

How does TikZ render an arc?



Multiple Indexes for collection - Only one works



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Catch multiple exceptions at once?firebase indexin method ? error in androidFirebase indexOn rules in unique keysFirebase Security Rules For A Node with Multiple ChildrenAdding and “.indexOn”: “.value” into Firebase RulesUsing an unspecified index. Consider adding “.indexOn”: “phone” at /use_frameworks_beta_2/searchIndex to your security rules for better performanceFirebase Index with Key as ParentIndex error in query in Firebaseunspecified index when searching data with firebase cloud function on nested object running nested QueryFirebase orderByChild with equalTo() doesn't work in javascript



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















First off, I'm kind of new to Firebase Database and coming from a SQL background.



I'm attempting to have a query that returns all notifications for a specified postID, regardless of which user the notification is for.



Essentially, if somebody deletes their post, I want to delete all of the "new post" notifications sent to all of their followers.



My data structure
enter image description here



I've tried these indexes..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
"$user_id":
".indexOn": ["timestamp", "objectId"]






I can query by timestamp with the following code, and it works fine.



 dbRef.GetChild("notificaton").GetChild(userID).GetQueryOrderedByChild("timestamp");


However, I don't want to use the userID in my query for post notifications. I've searched and tried a couple of other configurations for an index, but I just get errors in the firebase db admin that there are issues with my indexes.



I believe this is because I do need to query by timestamp, so that index needs to stay. So I need two indexes for the same collection, but different configurations because of user_id not being needed for the postID index.



I'm not sure how the index needs to be configured to be able to query on objectId regardless of user_id.



I've also tried something like this..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
".indexOn": ["objectId"]
,
"notification":
"$user_id":
".indexOn": ["timestamp"]






But I get an error Error saving rules: 'notification' occurs multiple times.



I've tried this..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
"$user_id":
".indexOn": ["timestamp"]
,
".indexOn": ["objectId"]





And Firebase seems OK with that, as it doesn't give an error, but it also doesn't return any data, which I assume is because objectId is not on the root notification collection.



So I'm stuck.










share|improve this question
























  • Can you tag your question with the language/platform you're coding on? That will at the very least highlight the code in your question, but frequently also allows us to better help you.

    – Frank van Puffelen
    Mar 22 at 14:26

















0















First off, I'm kind of new to Firebase Database and coming from a SQL background.



I'm attempting to have a query that returns all notifications for a specified postID, regardless of which user the notification is for.



Essentially, if somebody deletes their post, I want to delete all of the "new post" notifications sent to all of their followers.



My data structure
enter image description here



I've tried these indexes..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
"$user_id":
".indexOn": ["timestamp", "objectId"]






I can query by timestamp with the following code, and it works fine.



 dbRef.GetChild("notificaton").GetChild(userID).GetQueryOrderedByChild("timestamp");


However, I don't want to use the userID in my query for post notifications. I've searched and tried a couple of other configurations for an index, but I just get errors in the firebase db admin that there are issues with my indexes.



I believe this is because I do need to query by timestamp, so that index needs to stay. So I need two indexes for the same collection, but different configurations because of user_id not being needed for the postID index.



I'm not sure how the index needs to be configured to be able to query on objectId regardless of user_id.



I've also tried something like this..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
".indexOn": ["objectId"]
,
"notification":
"$user_id":
".indexOn": ["timestamp"]






But I get an error Error saving rules: 'notification' occurs multiple times.



I've tried this..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
"$user_id":
".indexOn": ["timestamp"]
,
".indexOn": ["objectId"]





And Firebase seems OK with that, as it doesn't give an error, but it also doesn't return any data, which I assume is because objectId is not on the root notification collection.



So I'm stuck.










share|improve this question
























  • Can you tag your question with the language/platform you're coding on? That will at the very least highlight the code in your question, but frequently also allows us to better help you.

    – Frank van Puffelen
    Mar 22 at 14:26













0












0








0








First off, I'm kind of new to Firebase Database and coming from a SQL background.



I'm attempting to have a query that returns all notifications for a specified postID, regardless of which user the notification is for.



Essentially, if somebody deletes their post, I want to delete all of the "new post" notifications sent to all of their followers.



My data structure
enter image description here



I've tried these indexes..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
"$user_id":
".indexOn": ["timestamp", "objectId"]






I can query by timestamp with the following code, and it works fine.



 dbRef.GetChild("notificaton").GetChild(userID).GetQueryOrderedByChild("timestamp");


However, I don't want to use the userID in my query for post notifications. I've searched and tried a couple of other configurations for an index, but I just get errors in the firebase db admin that there are issues with my indexes.



I believe this is because I do need to query by timestamp, so that index needs to stay. So I need two indexes for the same collection, but different configurations because of user_id not being needed for the postID index.



I'm not sure how the index needs to be configured to be able to query on objectId regardless of user_id.



I've also tried something like this..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
".indexOn": ["objectId"]
,
"notification":
"$user_id":
".indexOn": ["timestamp"]






But I get an error Error saving rules: 'notification' occurs multiple times.



I've tried this..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
"$user_id":
".indexOn": ["timestamp"]
,
".indexOn": ["objectId"]





And Firebase seems OK with that, as it doesn't give an error, but it also doesn't return any data, which I assume is because objectId is not on the root notification collection.



So I'm stuck.










share|improve this question
















First off, I'm kind of new to Firebase Database and coming from a SQL background.



I'm attempting to have a query that returns all notifications for a specified postID, regardless of which user the notification is for.



Essentially, if somebody deletes their post, I want to delete all of the "new post" notifications sent to all of their followers.



My data structure
enter image description here



I've tried these indexes..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
"$user_id":
".indexOn": ["timestamp", "objectId"]






I can query by timestamp with the following code, and it works fine.



 dbRef.GetChild("notificaton").GetChild(userID).GetQueryOrderedByChild("timestamp");


However, I don't want to use the userID in my query for post notifications. I've searched and tried a couple of other configurations for an index, but I just get errors in the firebase db admin that there are issues with my indexes.



I believe this is because I do need to query by timestamp, so that index needs to stay. So I need two indexes for the same collection, but different configurations because of user_id not being needed for the postID index.



I'm not sure how the index needs to be configured to be able to query on objectId regardless of user_id.



I've also tried something like this..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
".indexOn": ["objectId"]
,
"notification":
"$user_id":
".indexOn": ["timestamp"]






But I get an error Error saving rules: 'notification' occurs multiple times.



I've tried this..




"rules":
".read": "auth != null",
".write": "auth != null",
"notification":
"$user_id":
".indexOn": ["timestamp"]
,
".indexOn": ["objectId"]





And Firebase seems OK with that, as it doesn't give an error, but it also doesn't return any data, which I assume is because objectId is not on the root notification collection.



So I'm stuck.







c# firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 15:18







Ryan Alford

















asked Mar 22 at 12:42









Ryan AlfordRyan Alford

6,36843351




6,36843351












  • Can you tag your question with the language/platform you're coding on? That will at the very least highlight the code in your question, but frequently also allows us to better help you.

    – Frank van Puffelen
    Mar 22 at 14:26

















  • Can you tag your question with the language/platform you're coding on? That will at the very least highlight the code in your question, but frequently also allows us to better help you.

    – Frank van Puffelen
    Mar 22 at 14:26
















Can you tag your question with the language/platform you're coding on? That will at the very least highlight the code in your question, but frequently also allows us to better help you.

– Frank van Puffelen
Mar 22 at 14:26





Can you tag your question with the language/platform you're coding on? That will at the very least highlight the code in your question, but frequently also allows us to better help you.

– Frank van Puffelen
Mar 22 at 14:26












1 Answer
1






active

oldest

votes


















2














If you want to add indexes to each user of both the timestamp and the objectId of each of their child nodes, you can do so with:




"rules":
"notification":
"$user_id":
".indexOn": ["objectId", "timestamp"]






This allows you to query a user for child nodes with a matching objectId, or query a user for child nodes based on the timestamp.




Firebase queries always return direct child nodes of the location you run them on. That means that the orderByChild() clause of a query must refer to a fixed path to a single property of each direct child node. In other words: you cannot query a tree.



In your case that means that you cannot search across the notifications of all users with a single query. If you want to allow that query, you'll need to store a list of notifications for all users.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299861%2fmultiple-indexes-for-collection-only-one-works%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    If you want to add indexes to each user of both the timestamp and the objectId of each of their child nodes, you can do so with:




    "rules":
    "notification":
    "$user_id":
    ".indexOn": ["objectId", "timestamp"]






    This allows you to query a user for child nodes with a matching objectId, or query a user for child nodes based on the timestamp.




    Firebase queries always return direct child nodes of the location you run them on. That means that the orderByChild() clause of a query must refer to a fixed path to a single property of each direct child node. In other words: you cannot query a tree.



    In your case that means that you cannot search across the notifications of all users with a single query. If you want to allow that query, you'll need to store a list of notifications for all users.






    share|improve this answer



























      2














      If you want to add indexes to each user of both the timestamp and the objectId of each of their child nodes, you can do so with:




      "rules":
      "notification":
      "$user_id":
      ".indexOn": ["objectId", "timestamp"]






      This allows you to query a user for child nodes with a matching objectId, or query a user for child nodes based on the timestamp.




      Firebase queries always return direct child nodes of the location you run them on. That means that the orderByChild() clause of a query must refer to a fixed path to a single property of each direct child node. In other words: you cannot query a tree.



      In your case that means that you cannot search across the notifications of all users with a single query. If you want to allow that query, you'll need to store a list of notifications for all users.






      share|improve this answer

























        2












        2








        2







        If you want to add indexes to each user of both the timestamp and the objectId of each of their child nodes, you can do so with:




        "rules":
        "notification":
        "$user_id":
        ".indexOn": ["objectId", "timestamp"]






        This allows you to query a user for child nodes with a matching objectId, or query a user for child nodes based on the timestamp.




        Firebase queries always return direct child nodes of the location you run them on. That means that the orderByChild() clause of a query must refer to a fixed path to a single property of each direct child node. In other words: you cannot query a tree.



        In your case that means that you cannot search across the notifications of all users with a single query. If you want to allow that query, you'll need to store a list of notifications for all users.






        share|improve this answer













        If you want to add indexes to each user of both the timestamp and the objectId of each of their child nodes, you can do so with:




        "rules":
        "notification":
        "$user_id":
        ".indexOn": ["objectId", "timestamp"]






        This allows you to query a user for child nodes with a matching objectId, or query a user for child nodes based on the timestamp.




        Firebase queries always return direct child nodes of the location you run them on. That means that the orderByChild() clause of a query must refer to a fixed path to a single property of each direct child node. In other words: you cannot query a tree.



        In your case that means that you cannot search across the notifications of all users with a single query. If you want to allow that query, you'll need to store a list of notifications for all users.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 14:25









        Frank van PuffelenFrank van Puffelen

        248k31396423




        248k31396423





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299861%2fmultiple-indexes-for-collection-only-one-works%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현