Get name of months in which documents were created in MongoDB












0















I am building an budget app and I have spending records. Each record has startDate and endDate. Most spendings are day spending, like groceries, but some are temporary or permanent, like paying for rent.



I want to show years and months dropdown, were user chooses month and it shows spendings under that month. And I don't want to show months that don't have any spendings under it.



So, I need to query collection, so it would return months names/numbers under which there was records with start/endDate field.



Something like this.



{
_id: 1,
startDate: '08/10/2018',
endDate: '09/10/2018'
}

{
id: 2,
startDate: '11/10/2018',
endDate: '11/10/2018'
}


The result of the query should return



["08", "09", "11"]


Thank you!










share|improve this question




















  • 2





    What is the shape of your document, the general schema? Is the array shown here the actual shape? What is the affected collection size of the query? Are you querying millions of records or a few? Who is accessing this query and how often? {many, some, a few} users {many, some, a few} times? Where is the code running? Something load-balanced like a serverless architecture or a standalone server with limited memory? Is this maybe some one-off analytics task where performance isn't relevant?

    – nem035
    Jan 2 at 23:56













  • The shape is as above, with _id, startDate, andDate and bunch of other fields. It's not millions records, probably thousands. All users will access this query when they are opening their spending page. The code will run in AWS

    – user2960708
    Jan 3 at 0:07











  • Thousands in total or thousands per user? Can you just do this calculation in-memory?

    – nem035
    Jan 3 at 0:08











  • Also AWS has many services, do you know on which one is this running? Basically i'm exploring if you can do this calculation in-memory

    – nem035
    Jan 3 at 0:09






  • 1





    it will be better if startDate and endDate is Date type :P

    – huynhsamha
    Jan 3 at 0:23
















0















I am building an budget app and I have spending records. Each record has startDate and endDate. Most spendings are day spending, like groceries, but some are temporary or permanent, like paying for rent.



I want to show years and months dropdown, were user chooses month and it shows spendings under that month. And I don't want to show months that don't have any spendings under it.



So, I need to query collection, so it would return months names/numbers under which there was records with start/endDate field.



Something like this.



{
_id: 1,
startDate: '08/10/2018',
endDate: '09/10/2018'
}

{
id: 2,
startDate: '11/10/2018',
endDate: '11/10/2018'
}


The result of the query should return



["08", "09", "11"]


Thank you!










share|improve this question




















  • 2





    What is the shape of your document, the general schema? Is the array shown here the actual shape? What is the affected collection size of the query? Are you querying millions of records or a few? Who is accessing this query and how often? {many, some, a few} users {many, some, a few} times? Where is the code running? Something load-balanced like a serverless architecture or a standalone server with limited memory? Is this maybe some one-off analytics task where performance isn't relevant?

    – nem035
    Jan 2 at 23:56













  • The shape is as above, with _id, startDate, andDate and bunch of other fields. It's not millions records, probably thousands. All users will access this query when they are opening their spending page. The code will run in AWS

    – user2960708
    Jan 3 at 0:07











  • Thousands in total or thousands per user? Can you just do this calculation in-memory?

    – nem035
    Jan 3 at 0:08











  • Also AWS has many services, do you know on which one is this running? Basically i'm exploring if you can do this calculation in-memory

    – nem035
    Jan 3 at 0:09






  • 1





    it will be better if startDate and endDate is Date type :P

    – huynhsamha
    Jan 3 at 0:23














0












0








0








I am building an budget app and I have spending records. Each record has startDate and endDate. Most spendings are day spending, like groceries, but some are temporary or permanent, like paying for rent.



I want to show years and months dropdown, were user chooses month and it shows spendings under that month. And I don't want to show months that don't have any spendings under it.



So, I need to query collection, so it would return months names/numbers under which there was records with start/endDate field.



Something like this.



{
_id: 1,
startDate: '08/10/2018',
endDate: '09/10/2018'
}

{
id: 2,
startDate: '11/10/2018',
endDate: '11/10/2018'
}


The result of the query should return



["08", "09", "11"]


Thank you!










share|improve this question
















I am building an budget app and I have spending records. Each record has startDate and endDate. Most spendings are day spending, like groceries, but some are temporary or permanent, like paying for rent.



I want to show years and months dropdown, were user chooses month and it shows spendings under that month. And I don't want to show months that don't have any spendings under it.



So, I need to query collection, so it would return months names/numbers under which there was records with start/endDate field.



Something like this.



{
_id: 1,
startDate: '08/10/2018',
endDate: '09/10/2018'
}

{
id: 2,
startDate: '11/10/2018',
endDate: '11/10/2018'
}


The result of the query should return



["08", "09", "11"]


Thank you!







mongodb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 6:44









huynhsamha

843418




843418










asked Jan 2 at 23:48









user2960708user2960708

1592212




1592212








  • 2





    What is the shape of your document, the general schema? Is the array shown here the actual shape? What is the affected collection size of the query? Are you querying millions of records or a few? Who is accessing this query and how often? {many, some, a few} users {many, some, a few} times? Where is the code running? Something load-balanced like a serverless architecture or a standalone server with limited memory? Is this maybe some one-off analytics task where performance isn't relevant?

    – nem035
    Jan 2 at 23:56













  • The shape is as above, with _id, startDate, andDate and bunch of other fields. It's not millions records, probably thousands. All users will access this query when they are opening their spending page. The code will run in AWS

    – user2960708
    Jan 3 at 0:07











  • Thousands in total or thousands per user? Can you just do this calculation in-memory?

    – nem035
    Jan 3 at 0:08











  • Also AWS has many services, do you know on which one is this running? Basically i'm exploring if you can do this calculation in-memory

    – nem035
    Jan 3 at 0:09






  • 1





    it will be better if startDate and endDate is Date type :P

    – huynhsamha
    Jan 3 at 0:23














  • 2





    What is the shape of your document, the general schema? Is the array shown here the actual shape? What is the affected collection size of the query? Are you querying millions of records or a few? Who is accessing this query and how often? {many, some, a few} users {many, some, a few} times? Where is the code running? Something load-balanced like a serverless architecture or a standalone server with limited memory? Is this maybe some one-off analytics task where performance isn't relevant?

    – nem035
    Jan 2 at 23:56













  • The shape is as above, with _id, startDate, andDate and bunch of other fields. It's not millions records, probably thousands. All users will access this query when they are opening their spending page. The code will run in AWS

    – user2960708
    Jan 3 at 0:07











  • Thousands in total or thousands per user? Can you just do this calculation in-memory?

    – nem035
    Jan 3 at 0:08











  • Also AWS has many services, do you know on which one is this running? Basically i'm exploring if you can do this calculation in-memory

    – nem035
    Jan 3 at 0:09






  • 1





    it will be better if startDate and endDate is Date type :P

    – huynhsamha
    Jan 3 at 0:23








2




2





What is the shape of your document, the general schema? Is the array shown here the actual shape? What is the affected collection size of the query? Are you querying millions of records or a few? Who is accessing this query and how often? {many, some, a few} users {many, some, a few} times? Where is the code running? Something load-balanced like a serverless architecture or a standalone server with limited memory? Is this maybe some one-off analytics task where performance isn't relevant?

– nem035
Jan 2 at 23:56







What is the shape of your document, the general schema? Is the array shown here the actual shape? What is the affected collection size of the query? Are you querying millions of records or a few? Who is accessing this query and how often? {many, some, a few} users {many, some, a few} times? Where is the code running? Something load-balanced like a serverless architecture or a standalone server with limited memory? Is this maybe some one-off analytics task where performance isn't relevant?

– nem035
Jan 2 at 23:56















The shape is as above, with _id, startDate, andDate and bunch of other fields. It's not millions records, probably thousands. All users will access this query when they are opening their spending page. The code will run in AWS

– user2960708
Jan 3 at 0:07





The shape is as above, with _id, startDate, andDate and bunch of other fields. It's not millions records, probably thousands. All users will access this query when they are opening their spending page. The code will run in AWS

– user2960708
Jan 3 at 0:07













Thousands in total or thousands per user? Can you just do this calculation in-memory?

– nem035
Jan 3 at 0:08





Thousands in total or thousands per user? Can you just do this calculation in-memory?

– nem035
Jan 3 at 0:08













Also AWS has many services, do you know on which one is this running? Basically i'm exploring if you can do this calculation in-memory

– nem035
Jan 3 at 0:09





Also AWS has many services, do you know on which one is this running? Basically i'm exploring if you can do this calculation in-memory

– nem035
Jan 3 at 0:09




1




1





it will be better if startDate and endDate is Date type :P

– huynhsamha
Jan 3 at 0:23





it will be better if startDate and endDate is Date type :P

– huynhsamha
Jan 3 at 0:23












0






active

oldest

votes











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%2f54014667%2fget-name-of-months-in-which-documents-were-created-in-mongodb%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f54014667%2fget-name-of-months-in-which-documents-were-created-in-mongodb%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

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas