MongoDB Project Date ranges in mongoDB based on month or Quarter
up vote
0
down vote
favorite
Given a collection, I want to group ISODate by year and month and generate range of dates for each month.
For example if the dates are 10-10-2018, 11-10-2018, 11-10-2017, 04-04-2018
The output should be
{"ranges": [
{"min": 01-10-2018, "max": 31-10-2018},
{"min": 01-10-2017, "max": 31-10-2017},
{"min": 01-04-2018, "max": 31-04-2018},
]}
I could project month and year separately and group them and arrive at
[Oct 2018, Oct 2017....]
Is there a way to arrive at the above output using mongo aggregate query
mongodb mongodb-query pymongo
add a comment |
up vote
0
down vote
favorite
Given a collection, I want to group ISODate by year and month and generate range of dates for each month.
For example if the dates are 10-10-2018, 11-10-2018, 11-10-2017, 04-04-2018
The output should be
{"ranges": [
{"min": 01-10-2018, "max": 31-10-2018},
{"min": 01-10-2017, "max": 31-10-2017},
{"min": 01-04-2018, "max": 31-04-2018},
]}
I could project month and year separately and group them and arrive at
[Oct 2018, Oct 2017....]
Is there a way to arrive at the above output using mongo aggregate query
mongodb mongodb-query pymongo
docs.mongodb.com/manual/reference/operator/aggregation/…, then docs.mongodb.com/manual/reference/operator/aggregation/bucket if you know ranges or docs.mongodb.com/manual/reference/operator/aggregation/group if you don't.
– Alex Blex
Nov 8 at 9:48
None of the above. would work. My question is specifically to generate start and end date of a month given a month and year
– Bhavani Ravi
Nov 8 at 11:47
Use the first link. Start of the month is "%Y-%m-01" End of the month is beginning of next month - 1 day, then "%Y-%m-%d" of the result.
– Alex Blex
Nov 8 at 11:54
Nice idea thanks. Will try and get back
– Bhavani Ravi
Nov 8 at 12:23
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Given a collection, I want to group ISODate by year and month and generate range of dates for each month.
For example if the dates are 10-10-2018, 11-10-2018, 11-10-2017, 04-04-2018
The output should be
{"ranges": [
{"min": 01-10-2018, "max": 31-10-2018},
{"min": 01-10-2017, "max": 31-10-2017},
{"min": 01-04-2018, "max": 31-04-2018},
]}
I could project month and year separately and group them and arrive at
[Oct 2018, Oct 2017....]
Is there a way to arrive at the above output using mongo aggregate query
mongodb mongodb-query pymongo
Given a collection, I want to group ISODate by year and month and generate range of dates for each month.
For example if the dates are 10-10-2018, 11-10-2018, 11-10-2017, 04-04-2018
The output should be
{"ranges": [
{"min": 01-10-2018, "max": 31-10-2018},
{"min": 01-10-2017, "max": 31-10-2017},
{"min": 01-04-2018, "max": 31-04-2018},
]}
I could project month and year separately and group them and arrive at
[Oct 2018, Oct 2017....]
Is there a way to arrive at the above output using mongo aggregate query
mongodb mongodb-query pymongo
mongodb mongodb-query pymongo
asked Nov 8 at 9:26
Bhavani Ravi
682423
682423
docs.mongodb.com/manual/reference/operator/aggregation/…, then docs.mongodb.com/manual/reference/operator/aggregation/bucket if you know ranges or docs.mongodb.com/manual/reference/operator/aggregation/group if you don't.
– Alex Blex
Nov 8 at 9:48
None of the above. would work. My question is specifically to generate start and end date of a month given a month and year
– Bhavani Ravi
Nov 8 at 11:47
Use the first link. Start of the month is "%Y-%m-01" End of the month is beginning of next month - 1 day, then "%Y-%m-%d" of the result.
– Alex Blex
Nov 8 at 11:54
Nice idea thanks. Will try and get back
– Bhavani Ravi
Nov 8 at 12:23
add a comment |
docs.mongodb.com/manual/reference/operator/aggregation/…, then docs.mongodb.com/manual/reference/operator/aggregation/bucket if you know ranges or docs.mongodb.com/manual/reference/operator/aggregation/group if you don't.
– Alex Blex
Nov 8 at 9:48
None of the above. would work. My question is specifically to generate start and end date of a month given a month and year
– Bhavani Ravi
Nov 8 at 11:47
Use the first link. Start of the month is "%Y-%m-01" End of the month is beginning of next month - 1 day, then "%Y-%m-%d" of the result.
– Alex Blex
Nov 8 at 11:54
Nice idea thanks. Will try and get back
– Bhavani Ravi
Nov 8 at 12:23
docs.mongodb.com/manual/reference/operator/aggregation/…, then docs.mongodb.com/manual/reference/operator/aggregation/bucket if you know ranges or docs.mongodb.com/manual/reference/operator/aggregation/group if you don't.
– Alex Blex
Nov 8 at 9:48
docs.mongodb.com/manual/reference/operator/aggregation/…, then docs.mongodb.com/manual/reference/operator/aggregation/bucket if you know ranges or docs.mongodb.com/manual/reference/operator/aggregation/group if you don't.
– Alex Blex
Nov 8 at 9:48
None of the above. would work. My question is specifically to generate start and end date of a month given a month and year
– Bhavani Ravi
Nov 8 at 11:47
None of the above. would work. My question is specifically to generate start and end date of a month given a month and year
– Bhavani Ravi
Nov 8 at 11:47
Use the first link. Start of the month is "%Y-%m-01" End of the month is beginning of next month - 1 day, then "%Y-%m-%d" of the result.
– Alex Blex
Nov 8 at 11:54
Use the first link. Start of the month is "%Y-%m-01" End of the month is beginning of next month - 1 day, then "%Y-%m-%d" of the result.
– Alex Blex
Nov 8 at 11:54
Nice idea thanks. Will try and get back
– Bhavani Ravi
Nov 8 at 12:23
Nice idea thanks. Will try and get back
– Bhavani Ravi
Nov 8 at 12:23
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53204790%2fmongodb-project-date-ranges-in-mongodb-based-on-month-or-quarter%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
docs.mongodb.com/manual/reference/operator/aggregation/…, then docs.mongodb.com/manual/reference/operator/aggregation/bucket if you know ranges or docs.mongodb.com/manual/reference/operator/aggregation/group if you don't.
– Alex Blex
Nov 8 at 9:48
None of the above. would work. My question is specifically to generate start and end date of a month given a month and year
– Bhavani Ravi
Nov 8 at 11:47
Use the first link. Start of the month is "%Y-%m-01" End of the month is beginning of next month - 1 day, then "%Y-%m-%d" of the result.
– Alex Blex
Nov 8 at 11:54
Nice idea thanks. Will try and get back
– Bhavani Ravi
Nov 8 at 12:23