How do you figure out how many documents are created per hour in a Firestore collection?
What is the best way to figure out how many documents are being created per hour into a Firestore collection. I have created a cloud functions which counts each time a document is added or removed but I can't seem to find a way to figure out the rate at which this is occurring.
firebase nosql google-cloud-firestore google-cloud-functions
add a comment |
What is the best way to figure out how many documents are being created per hour into a Firestore collection. I have created a cloud functions which counts each time a document is added or removed but I can't seem to find a way to figure out the rate at which this is occurring.
firebase nosql google-cloud-firestore google-cloud-functions
In the last hour or in every hour?
– Alex Mamo
Nov 28 '18 at 11:45
@AlexMamo I would like to figure out how many documents have been created in the last hour. It should be a dynamic value.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 18:24
add a comment |
What is the best way to figure out how many documents are being created per hour into a Firestore collection. I have created a cloud functions which counts each time a document is added or removed but I can't seem to find a way to figure out the rate at which this is occurring.
firebase nosql google-cloud-firestore google-cloud-functions
What is the best way to figure out how many documents are being created per hour into a Firestore collection. I have created a cloud functions which counts each time a document is added or removed but I can't seem to find a way to figure out the rate at which this is occurring.
firebase nosql google-cloud-firestore google-cloud-functions
firebase nosql google-cloud-firestore google-cloud-functions
asked Nov 27 '18 at 19:48
TheRedCamaro3.0 3.0TheRedCamaro3.0 3.0
1709
1709
In the last hour or in every hour?
– Alex Mamo
Nov 28 '18 at 11:45
@AlexMamo I would like to figure out how many documents have been created in the last hour. It should be a dynamic value.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 18:24
add a comment |
In the last hour or in every hour?
– Alex Mamo
Nov 28 '18 at 11:45
@AlexMamo I would like to figure out how many documents have been created in the last hour. It should be a dynamic value.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 18:24
In the last hour or in every hour?
– Alex Mamo
Nov 28 '18 at 11:45
In the last hour or in every hour?
– Alex Mamo
Nov 28 '18 at 11:45
@AlexMamo I would like to figure out how many documents have been created in the last hour. It should be a dynamic value.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 18:24
@AlexMamo I would like to figure out how many documents have been created in the last hour. It should be a dynamic value.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 18:24
add a comment |
1 Answer
1
active
oldest
votes
To solve this, you should add to each document in your collection a new property of type Date
, that should hold the date and time of its creation. Now you can create a function, in Cloud Functions for Firebase that will add to a location in your database the number of documents added in the last hour. You can write this number in a Firebase realtime database rather than in Cloud Firestore, according to the last part of my answer within this post.
The function should actually count the number of documents using a query that look like this:
var today = new Date();
var lastHour = date.setDate(today.getDate() - 3600);
db.collection("nameOfCollection").where("date", ">", lastHour);
You can trigger this function using cron-job.org service.
Thank you for taking the time to answer this question. I appreciate your detailed response. I was wondering would it be possible to implement a metadata document for the collection containing the number of posts per hour updated in a similar fashion to this answer for large data sets stackoverflow.com/a/49407570/9367155 without having to query the whole database each time and count the snapshot, as with using chron-job this query would be performed every minute.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:34
Also Excellent answer on stackoverflow.com/questions/48534676/… out of curiosity when you are talking about limits is sharding free in firebase but costly in firestore?
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:35
You're welcome! I think it could. I didn't personally try it but it might work. You can give it a try. Regarding you second comment, yes, that's correct. If you think that my answer from that post was helpful, please consider give a vote-up. I'd appreciate it. Thanks!
– Alex Mamo
Nov 28 '18 at 19:44
Hi! Is there everything alright, can I help you with other informations? If you think that my answer helped you, please consider accepting it by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!
– Alex Mamo
Nov 29 '18 at 10:28
Thank you for all of your help. Regarding the sharding, if I use Firebase real time database to store the counter instead of firestore would I still have to shard the data as is done here firebase.google.com/docs/firestore/solutions/counters or could I just make a counter node that constantly updates. Again thank you for all of your help.
– TheRedCamaro3.0 3.0
Nov 29 '18 at 19:15
|
show 1 more 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%2f53507083%2fhow-do-you-figure-out-how-many-documents-are-created-per-hour-in-a-firestore-col%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
To solve this, you should add to each document in your collection a new property of type Date
, that should hold the date and time of its creation. Now you can create a function, in Cloud Functions for Firebase that will add to a location in your database the number of documents added in the last hour. You can write this number in a Firebase realtime database rather than in Cloud Firestore, according to the last part of my answer within this post.
The function should actually count the number of documents using a query that look like this:
var today = new Date();
var lastHour = date.setDate(today.getDate() - 3600);
db.collection("nameOfCollection").where("date", ">", lastHour);
You can trigger this function using cron-job.org service.
Thank you for taking the time to answer this question. I appreciate your detailed response. I was wondering would it be possible to implement a metadata document for the collection containing the number of posts per hour updated in a similar fashion to this answer for large data sets stackoverflow.com/a/49407570/9367155 without having to query the whole database each time and count the snapshot, as with using chron-job this query would be performed every minute.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:34
Also Excellent answer on stackoverflow.com/questions/48534676/… out of curiosity when you are talking about limits is sharding free in firebase but costly in firestore?
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:35
You're welcome! I think it could. I didn't personally try it but it might work. You can give it a try. Regarding you second comment, yes, that's correct. If you think that my answer from that post was helpful, please consider give a vote-up. I'd appreciate it. Thanks!
– Alex Mamo
Nov 28 '18 at 19:44
Hi! Is there everything alright, can I help you with other informations? If you think that my answer helped you, please consider accepting it by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!
– Alex Mamo
Nov 29 '18 at 10:28
Thank you for all of your help. Regarding the sharding, if I use Firebase real time database to store the counter instead of firestore would I still have to shard the data as is done here firebase.google.com/docs/firestore/solutions/counters or could I just make a counter node that constantly updates. Again thank you for all of your help.
– TheRedCamaro3.0 3.0
Nov 29 '18 at 19:15
|
show 1 more comment
To solve this, you should add to each document in your collection a new property of type Date
, that should hold the date and time of its creation. Now you can create a function, in Cloud Functions for Firebase that will add to a location in your database the number of documents added in the last hour. You can write this number in a Firebase realtime database rather than in Cloud Firestore, according to the last part of my answer within this post.
The function should actually count the number of documents using a query that look like this:
var today = new Date();
var lastHour = date.setDate(today.getDate() - 3600);
db.collection("nameOfCollection").where("date", ">", lastHour);
You can trigger this function using cron-job.org service.
Thank you for taking the time to answer this question. I appreciate your detailed response. I was wondering would it be possible to implement a metadata document for the collection containing the number of posts per hour updated in a similar fashion to this answer for large data sets stackoverflow.com/a/49407570/9367155 without having to query the whole database each time and count the snapshot, as with using chron-job this query would be performed every minute.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:34
Also Excellent answer on stackoverflow.com/questions/48534676/… out of curiosity when you are talking about limits is sharding free in firebase but costly in firestore?
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:35
You're welcome! I think it could. I didn't personally try it but it might work. You can give it a try. Regarding you second comment, yes, that's correct. If you think that my answer from that post was helpful, please consider give a vote-up. I'd appreciate it. Thanks!
– Alex Mamo
Nov 28 '18 at 19:44
Hi! Is there everything alright, can I help you with other informations? If you think that my answer helped you, please consider accepting it by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!
– Alex Mamo
Nov 29 '18 at 10:28
Thank you for all of your help. Regarding the sharding, if I use Firebase real time database to store the counter instead of firestore would I still have to shard the data as is done here firebase.google.com/docs/firestore/solutions/counters or could I just make a counter node that constantly updates. Again thank you for all of your help.
– TheRedCamaro3.0 3.0
Nov 29 '18 at 19:15
|
show 1 more comment
To solve this, you should add to each document in your collection a new property of type Date
, that should hold the date and time of its creation. Now you can create a function, in Cloud Functions for Firebase that will add to a location in your database the number of documents added in the last hour. You can write this number in a Firebase realtime database rather than in Cloud Firestore, according to the last part of my answer within this post.
The function should actually count the number of documents using a query that look like this:
var today = new Date();
var lastHour = date.setDate(today.getDate() - 3600);
db.collection("nameOfCollection").where("date", ">", lastHour);
You can trigger this function using cron-job.org service.
To solve this, you should add to each document in your collection a new property of type Date
, that should hold the date and time of its creation. Now you can create a function, in Cloud Functions for Firebase that will add to a location in your database the number of documents added in the last hour. You can write this number in a Firebase realtime database rather than in Cloud Firestore, according to the last part of my answer within this post.
The function should actually count the number of documents using a query that look like this:
var today = new Date();
var lastHour = date.setDate(today.getDate() - 3600);
db.collection("nameOfCollection").where("date", ">", lastHour);
You can trigger this function using cron-job.org service.
answered Nov 28 '18 at 18:53
Alex MamoAlex Mamo
45.1k82863
45.1k82863
Thank you for taking the time to answer this question. I appreciate your detailed response. I was wondering would it be possible to implement a metadata document for the collection containing the number of posts per hour updated in a similar fashion to this answer for large data sets stackoverflow.com/a/49407570/9367155 without having to query the whole database each time and count the snapshot, as with using chron-job this query would be performed every minute.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:34
Also Excellent answer on stackoverflow.com/questions/48534676/… out of curiosity when you are talking about limits is sharding free in firebase but costly in firestore?
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:35
You're welcome! I think it could. I didn't personally try it but it might work. You can give it a try. Regarding you second comment, yes, that's correct. If you think that my answer from that post was helpful, please consider give a vote-up. I'd appreciate it. Thanks!
– Alex Mamo
Nov 28 '18 at 19:44
Hi! Is there everything alright, can I help you with other informations? If you think that my answer helped you, please consider accepting it by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!
– Alex Mamo
Nov 29 '18 at 10:28
Thank you for all of your help. Regarding the sharding, if I use Firebase real time database to store the counter instead of firestore would I still have to shard the data as is done here firebase.google.com/docs/firestore/solutions/counters or could I just make a counter node that constantly updates. Again thank you for all of your help.
– TheRedCamaro3.0 3.0
Nov 29 '18 at 19:15
|
show 1 more comment
Thank you for taking the time to answer this question. I appreciate your detailed response. I was wondering would it be possible to implement a metadata document for the collection containing the number of posts per hour updated in a similar fashion to this answer for large data sets stackoverflow.com/a/49407570/9367155 without having to query the whole database each time and count the snapshot, as with using chron-job this query would be performed every minute.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:34
Also Excellent answer on stackoverflow.com/questions/48534676/… out of curiosity when you are talking about limits is sharding free in firebase but costly in firestore?
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:35
You're welcome! I think it could. I didn't personally try it but it might work. You can give it a try. Regarding you second comment, yes, that's correct. If you think that my answer from that post was helpful, please consider give a vote-up. I'd appreciate it. Thanks!
– Alex Mamo
Nov 28 '18 at 19:44
Hi! Is there everything alright, can I help you with other informations? If you think that my answer helped you, please consider accepting it by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!
– Alex Mamo
Nov 29 '18 at 10:28
Thank you for all of your help. Regarding the sharding, if I use Firebase real time database to store the counter instead of firestore would I still have to shard the data as is done here firebase.google.com/docs/firestore/solutions/counters or could I just make a counter node that constantly updates. Again thank you for all of your help.
– TheRedCamaro3.0 3.0
Nov 29 '18 at 19:15
Thank you for taking the time to answer this question. I appreciate your detailed response. I was wondering would it be possible to implement a metadata document for the collection containing the number of posts per hour updated in a similar fashion to this answer for large data sets stackoverflow.com/a/49407570/9367155 without having to query the whole database each time and count the snapshot, as with using chron-job this query would be performed every minute.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:34
Thank you for taking the time to answer this question. I appreciate your detailed response. I was wondering would it be possible to implement a metadata document for the collection containing the number of posts per hour updated in a similar fashion to this answer for large data sets stackoverflow.com/a/49407570/9367155 without having to query the whole database each time and count the snapshot, as with using chron-job this query would be performed every minute.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:34
Also Excellent answer on stackoverflow.com/questions/48534676/… out of curiosity when you are talking about limits is sharding free in firebase but costly in firestore?
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:35
Also Excellent answer on stackoverflow.com/questions/48534676/… out of curiosity when you are talking about limits is sharding free in firebase but costly in firestore?
– TheRedCamaro3.0 3.0
Nov 28 '18 at 19:35
You're welcome! I think it could. I didn't personally try it but it might work. You can give it a try. Regarding you second comment, yes, that's correct. If you think that my answer from that post was helpful, please consider give a vote-up. I'd appreciate it. Thanks!
– Alex Mamo
Nov 28 '18 at 19:44
You're welcome! I think it could. I didn't personally try it but it might work. You can give it a try. Regarding you second comment, yes, that's correct. If you think that my answer from that post was helpful, please consider give a vote-up. I'd appreciate it. Thanks!
– Alex Mamo
Nov 28 '18 at 19:44
Hi! Is there everything alright, can I help you with other informations? If you think that my answer helped you, please consider accepting it by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!
– Alex Mamo
Nov 29 '18 at 10:28
Hi! Is there everything alright, can I help you with other informations? If you think that my answer helped you, please consider accepting it by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!
– Alex Mamo
Nov 29 '18 at 10:28
Thank you for all of your help. Regarding the sharding, if I use Firebase real time database to store the counter instead of firestore would I still have to shard the data as is done here firebase.google.com/docs/firestore/solutions/counters or could I just make a counter node that constantly updates. Again thank you for all of your help.
– TheRedCamaro3.0 3.0
Nov 29 '18 at 19:15
Thank you for all of your help. Regarding the sharding, if I use Firebase real time database to store the counter instead of firestore would I still have to shard the data as is done here firebase.google.com/docs/firestore/solutions/counters or could I just make a counter node that constantly updates. Again thank you for all of your help.
– TheRedCamaro3.0 3.0
Nov 29 '18 at 19:15
|
show 1 more 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%2f53507083%2fhow-do-you-figure-out-how-many-documents-are-created-per-hour-in-a-firestore-col%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
In the last hour or in every hour?
– Alex Mamo
Nov 28 '18 at 11:45
@AlexMamo I would like to figure out how many documents have been created in the last hour. It should be a dynamic value.
– TheRedCamaro3.0 3.0
Nov 28 '18 at 18:24