Python, MongoDB aggregate within the range start to end [duplicate]
This question already has an answer here:
Find objects between two dates MongoDB
11 answers
Mongodb query specific month|year not date
4 answers
I am trying to write a mongo query in python to get the monthly and weekly range from days.
So far I have
my_collection.find({
'date':{
'$gte': date_start,
'$lte': date_end
}
}
It returns the day range between date_start and date_end, I tried to use '$month': 'gte', 'lte' but is not working, does anyone has any ideas how to get monthly and weekly based on the start date and end? The date_start and date_end are datetime objects.
Example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end): 01, 02, 03, 04, 05, 06 ..
I just went through the same examples that has been asked before and what I asked is different, in my situation I have two dates, start and end.. now from this two dates I just want to display the month by combining the two dates together.. so far I haven't seen an example of how to do it.
Thanks
python mongodb aggregate
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 20:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Find objects between two dates MongoDB
11 answers
Mongodb query specific month|year not date
4 answers
I am trying to write a mongo query in python to get the monthly and weekly range from days.
So far I have
my_collection.find({
'date':{
'$gte': date_start,
'$lte': date_end
}
}
It returns the day range between date_start and date_end, I tried to use '$month': 'gte', 'lte' but is not working, does anyone has any ideas how to get monthly and weekly based on the start date and end? The date_start and date_end are datetime objects.
Example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end): 01, 02, 03, 04, 05, 06 ..
I just went through the same examples that has been asked before and what I asked is different, in my situation I have two dates, start and end.. now from this two dates I just want to display the month by combining the two dates together.. so far I haven't seen an example of how to do it.
Thanks
python mongodb aggregate
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 20:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
how are you keeping your data?? please add some explanation about your objects in the database, i.e. add a sample data objects and the result you want from the query, you question seems a bit unclear
– Mohammad Ganji
Nov 23 '18 at 14:56
The data is saved in mongodb, an example of the data is : datetime.datetime(2017, 2, 8, 10, 0, 25). Result that I want: example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end).
– Michael
Nov 23 '18 at 14:58
$month
is not something you should use in a$match
expression. The best advice it keep the "range query" in the match, and then simply$project
the using$month
to you have that value. Attempting something like "select november for every year" is really bad for performance, and if that was your intent then you are better off storing "month" within your document as separate field. Plenty of examples of$month
usage, including documentation.
– Neil Lunn
Nov 23 '18 at 20:41
Neil I tried what you said and is not working: collection.find('$project': {'$month' : { '$gte': start, '$lte' : end }}
– Michael
Nov 26 '18 at 9:48
add a comment |
This question already has an answer here:
Find objects between two dates MongoDB
11 answers
Mongodb query specific month|year not date
4 answers
I am trying to write a mongo query in python to get the monthly and weekly range from days.
So far I have
my_collection.find({
'date':{
'$gte': date_start,
'$lte': date_end
}
}
It returns the day range between date_start and date_end, I tried to use '$month': 'gte', 'lte' but is not working, does anyone has any ideas how to get monthly and weekly based on the start date and end? The date_start and date_end are datetime objects.
Example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end): 01, 02, 03, 04, 05, 06 ..
I just went through the same examples that has been asked before and what I asked is different, in my situation I have two dates, start and end.. now from this two dates I just want to display the month by combining the two dates together.. so far I haven't seen an example of how to do it.
Thanks
python mongodb aggregate
This question already has an answer here:
Find objects between two dates MongoDB
11 answers
Mongodb query specific month|year not date
4 answers
I am trying to write a mongo query in python to get the monthly and weekly range from days.
So far I have
my_collection.find({
'date':{
'$gte': date_start,
'$lte': date_end
}
}
It returns the day range between date_start and date_end, I tried to use '$month': 'gte', 'lte' but is not working, does anyone has any ideas how to get monthly and weekly based on the start date and end? The date_start and date_end are datetime objects.
Example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end): 01, 02, 03, 04, 05, 06 ..
I just went through the same examples that has been asked before and what I asked is different, in my situation I have two dates, start and end.. now from this two dates I just want to display the month by combining the two dates together.. so far I haven't seen an example of how to do it.
Thanks
This question already has an answer here:
Find objects between two dates MongoDB
11 answers
Mongodb query specific month|year not date
4 answers
python mongodb aggregate
python mongodb aggregate
edited Nov 26 '18 at 9:42
Michael
asked Nov 23 '18 at 14:35
MichaelMichael
164
164
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 20:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 20:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
how are you keeping your data?? please add some explanation about your objects in the database, i.e. add a sample data objects and the result you want from the query, you question seems a bit unclear
– Mohammad Ganji
Nov 23 '18 at 14:56
The data is saved in mongodb, an example of the data is : datetime.datetime(2017, 2, 8, 10, 0, 25). Result that I want: example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end).
– Michael
Nov 23 '18 at 14:58
$month
is not something you should use in a$match
expression. The best advice it keep the "range query" in the match, and then simply$project
the using$month
to you have that value. Attempting something like "select november for every year" is really bad for performance, and if that was your intent then you are better off storing "month" within your document as separate field. Plenty of examples of$month
usage, including documentation.
– Neil Lunn
Nov 23 '18 at 20:41
Neil I tried what you said and is not working: collection.find('$project': {'$month' : { '$gte': start, '$lte' : end }}
– Michael
Nov 26 '18 at 9:48
add a comment |
how are you keeping your data?? please add some explanation about your objects in the database, i.e. add a sample data objects and the result you want from the query, you question seems a bit unclear
– Mohammad Ganji
Nov 23 '18 at 14:56
The data is saved in mongodb, an example of the data is : datetime.datetime(2017, 2, 8, 10, 0, 25). Result that I want: example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end).
– Michael
Nov 23 '18 at 14:58
$month
is not something you should use in a$match
expression. The best advice it keep the "range query" in the match, and then simply$project
the using$month
to you have that value. Attempting something like "select november for every year" is really bad for performance, and if that was your intent then you are better off storing "month" within your document as separate field. Plenty of examples of$month
usage, including documentation.
– Neil Lunn
Nov 23 '18 at 20:41
Neil I tried what you said and is not working: collection.find('$project': {'$month' : { '$gte': start, '$lte' : end }}
– Michael
Nov 26 '18 at 9:48
how are you keeping your data?? please add some explanation about your objects in the database, i.e. add a sample data objects and the result you want from the query, you question seems a bit unclear
– Mohammad Ganji
Nov 23 '18 at 14:56
how are you keeping your data?? please add some explanation about your objects in the database, i.e. add a sample data objects and the result you want from the query, you question seems a bit unclear
– Mohammad Ganji
Nov 23 '18 at 14:56
The data is saved in mongodb, an example of the data is : datetime.datetime(2017, 2, 8, 10, 0, 25). Result that I want: example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end).
– Michael
Nov 23 '18 at 14:58
The data is saved in mongodb, an example of the data is : datetime.datetime(2017, 2, 8, 10, 0, 25). Result that I want: example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end).
– Michael
Nov 23 '18 at 14:58
$month
is not something you should use in a $match
expression. The best advice it keep the "range query" in the match, and then simply $project
the using $month
to you have that value. Attempting something like "select november for every year" is really bad for performance, and if that was your intent then you are better off storing "month" within your document as separate field. Plenty of examples of $month
usage, including documentation.– Neil Lunn
Nov 23 '18 at 20:41
$month
is not something you should use in a $match
expression. The best advice it keep the "range query" in the match, and then simply $project
the using $month
to you have that value. Attempting something like "select november for every year" is really bad for performance, and if that was your intent then you are better off storing "month" within your document as separate field. Plenty of examples of $month
usage, including documentation.– Neil Lunn
Nov 23 '18 at 20:41
Neil I tried what you said and is not working: collection.find('$project': {'$month' : { '$gte': start, '$lte' : end }}
– Michael
Nov 26 '18 at 9:48
Neil I tried what you said and is not working: collection.find('$project': {'$month' : { '$gte': start, '$lte' : end }}
– Michael
Nov 26 '18 at 9:48
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
how are you keeping your data?? please add some explanation about your objects in the database, i.e. add a sample data objects and the result you want from the query, you question seems a bit unclear
– Mohammad Ganji
Nov 23 '18 at 14:56
The data is saved in mongodb, an example of the data is : datetime.datetime(2017, 2, 8, 10, 0, 25). Result that I want: example ( date_start = 2017-01-01, date_end = 2017-12-01) I want to return just the month between this two range(start, end).
– Michael
Nov 23 '18 at 14:58
$month
is not something you should use in a$match
expression. The best advice it keep the "range query" in the match, and then simply$project
the using$month
to you have that value. Attempting something like "select november for every year" is really bad for performance, and if that was your intent then you are better off storing "month" within your document as separate field. Plenty of examples of$month
usage, including documentation.– Neil Lunn
Nov 23 '18 at 20:41
Neil I tried what you said and is not working: collection.find('$project': {'$month' : { '$gte': start, '$lte' : end }}
– Michael
Nov 26 '18 at 9:48