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;
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
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
add a comment |
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
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
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
add a comment |
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
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
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
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
c# firebase firebase-realtime-database
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 22 at 14:25
Frank van PuffelenFrank van Puffelen
248k31396423
248k31396423
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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