Find last record of each dayget last record less than or equal in meteor? This means that I want to download all records for every item, but only the last record of each itemHow to aggregate this query correctly in MongoDb?Group result by 15 minutes time interval in MongoDbRandom record from MongoDBFind objects between two dates MongoDBHow to get the last N records in mongodb?How can I use mongodump to dump out records matching a specific date range?“Large data” work flows using pandasFind MongoDB records where array field is not emptyLatest record by date for each item mongodb groupSort the data in mongo collection based on TimestampHow to Get last 5 Days Data with all FieldsHow do I get the earliest record by date for a unique constraint?

Polyhedra, Polyhedron, Polytopes and Polygon

How many oliphaunts died in all of the Lord of the Rings battles?

Why does Canada require mandatory bilingualism in all government posts?

Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?

Correlation length anisotropy in the 2D Ising model

How do I explain an exponentially complex intuitively?

Why force the nose of 737 Max down in the first place?

The Sword in the Stone

How could Nomadic scholars effectively memorize libraries worth of information

Learning Minor scales through 7 patterns (Guitar)

How to store my pliers and wire cutters on my desk?

How to avoid theft of potentially patentable IP when trying to obtain a Ph.D?

Why is the number of local variables used in a Java bytecode method not the most economical?

Seaborn style plot of pandas dataframe

Why did House of Representatives need to condemn Trumps Tweets?

Japanese reading of an integer

Decreasing star count

Copying an existing HTML page and use it, is that against any copyright law?

Why is it considered Acid Rain with pH <5.6

Sea level static test of an upper stage possible?

What does "see" in "the Holy See" mean?

Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?

Why can't my huge trees be chopped down?

Isolated audio without a transformer



Find last record of each day


get last record less than or equal in meteor? This means that I want to download all records for every item, but only the last record of each itemHow to aggregate this query correctly in MongoDb?Group result by 15 minutes time interval in MongoDbRandom record from MongoDBFind objects between two dates MongoDBHow to get the last N records in mongodb?How can I use mongodump to dump out records matching a specific date range?“Large data” work flows using pandasFind MongoDB records where array field is not emptyLatest record by date for each item mongodb groupSort the data in mongo collection based on TimestampHow to Get last 5 Days Data with all FieldsHow do I get the earliest record by date for a unique constraint?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I use mongodb (I'm new in mongodb) to store data about my power consumption , each minute there is a new record, here is an example :



"id":"5309d4cae4b0fbd904cc00e1","adco":"O","hchc":7267599,"hchp":10805900,"hhphc":"g","ptec":"c","iinst":13,"papp":3010,"imax":58,"optarif":"s","isousc":60,"motdetat":"Á","date":1393156826114


so I have around 1440 records a day.



I want to compute the cost by day, but the problem for this is that I need the last record of the day, because this record can give me the amount of absolute kWh (kiloWatt-Hour). So if I remove the kwh amount of the last record of the yesterday, I have the amount of kWh for the day.



The field hchp gives me this absolute kWh. The field date corresponds to the time of the measure in millisecond.




consumption of the day = absolute consumption of the end of the day - absolute consumption of the end of yesterday.




How is it possible to get the last record of each day in mongodb ?



Note : I use mongodb in spring java, so I need a query like this :



Example to get all measures :



@Query(" 'date' : $gt : ?0 ")
public List<Mesure> findByDateGreaterThan(Date date, Sort sort);









share|improve this question
























  • Have you looked at getting a range representing the date, and then, sorting and limiting to the highest date value?

    – WiredPrairie
    Mar 5 '14 at 18:00

















3















I use mongodb (I'm new in mongodb) to store data about my power consumption , each minute there is a new record, here is an example :



"id":"5309d4cae4b0fbd904cc00e1","adco":"O","hchc":7267599,"hchp":10805900,"hhphc":"g","ptec":"c","iinst":13,"papp":3010,"imax":58,"optarif":"s","isousc":60,"motdetat":"Á","date":1393156826114


so I have around 1440 records a day.



I want to compute the cost by day, but the problem for this is that I need the last record of the day, because this record can give me the amount of absolute kWh (kiloWatt-Hour). So if I remove the kwh amount of the last record of the yesterday, I have the amount of kWh for the day.



The field hchp gives me this absolute kWh. The field date corresponds to the time of the measure in millisecond.




consumption of the day = absolute consumption of the end of the day - absolute consumption of the end of yesterday.




How is it possible to get the last record of each day in mongodb ?



Note : I use mongodb in spring java, so I need a query like this :



Example to get all measures :



@Query(" 'date' : $gt : ?0 ")
public List<Mesure> findByDateGreaterThan(Date date, Sort sort);









share|improve this question
























  • Have you looked at getting a range representing the date, and then, sorting and limiting to the highest date value?

    – WiredPrairie
    Mar 5 '14 at 18:00













3












3








3


1






I use mongodb (I'm new in mongodb) to store data about my power consumption , each minute there is a new record, here is an example :



"id":"5309d4cae4b0fbd904cc00e1","adco":"O","hchc":7267599,"hchp":10805900,"hhphc":"g","ptec":"c","iinst":13,"papp":3010,"imax":58,"optarif":"s","isousc":60,"motdetat":"Á","date":1393156826114


so I have around 1440 records a day.



I want to compute the cost by day, but the problem for this is that I need the last record of the day, because this record can give me the amount of absolute kWh (kiloWatt-Hour). So if I remove the kwh amount of the last record of the yesterday, I have the amount of kWh for the day.



The field hchp gives me this absolute kWh. The field date corresponds to the time of the measure in millisecond.




consumption of the day = absolute consumption of the end of the day - absolute consumption of the end of yesterday.




How is it possible to get the last record of each day in mongodb ?



Note : I use mongodb in spring java, so I need a query like this :



Example to get all measures :



@Query(" 'date' : $gt : ?0 ")
public List<Mesure> findByDateGreaterThan(Date date, Sort sort);









share|improve this question
















I use mongodb (I'm new in mongodb) to store data about my power consumption , each minute there is a new record, here is an example :



"id":"5309d4cae4b0fbd904cc00e1","adco":"O","hchc":7267599,"hchp":10805900,"hhphc":"g","ptec":"c","iinst":13,"papp":3010,"imax":58,"optarif":"s","isousc":60,"motdetat":"Á","date":1393156826114


so I have around 1440 records a day.



I want to compute the cost by day, but the problem for this is that I need the last record of the day, because this record can give me the amount of absolute kWh (kiloWatt-Hour). So if I remove the kwh amount of the last record of the yesterday, I have the amount of kWh for the day.



The field hchp gives me this absolute kWh. The field date corresponds to the time of the measure in millisecond.




consumption of the day = absolute consumption of the end of the day - absolute consumption of the end of yesterday.




How is it possible to get the last record of each day in mongodb ?



Note : I use mongodb in spring java, so I need a query like this :



Example to get all measures :



@Query(" 'date' : $gt : ?0 ")
public List<Mesure> findByDateGreaterThan(Date date, Sort sort);






mongodb mongodb-query aggregation-framework






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 26 '17 at 10:31









Neil Lunn

105k24 gold badges194 silver badges198 bronze badges




105k24 gold badges194 silver badges198 bronze badges










asked Mar 5 '14 at 16:06









elolozoneelolozone

163 bronze badges




163 bronze badges












  • Have you looked at getting a range representing the date, and then, sorting and limiting to the highest date value?

    – WiredPrairie
    Mar 5 '14 at 18:00

















  • Have you looked at getting a range representing the date, and then, sorting and limiting to the highest date value?

    – WiredPrairie
    Mar 5 '14 at 18:00
















Have you looked at getting a range representing the date, and then, sorting and limiting to the highest date value?

– WiredPrairie
Mar 5 '14 at 18:00





Have you looked at getting a range representing the date, and then, sorting and limiting to the highest date value?

– WiredPrairie
Mar 5 '14 at 18:00












1 Answer
1






active

oldest

votes


















3














A bit more modern than the original answer:



db.collection.aggregate([
"$sort": "date": 1 ,
"$group":
"_id":
"$subtract": ["$date","$mod": ["$date",86400000]]
,
"doc": "$last": "$$ROOT"
,
"$replaceRoot": "newDocument": "$doc"
])


The same principle applies that you essentially $sort the collection and then $group on the required grouping key picking up the $last data from the grouping boundary.



Making things a bit clearer since the original writing is that you can use $$ROOT instead of specifying every document property, and of course the $replaceRoot stage allows you to restore that data fully as the original document form.



But the general solution is still $sort first, then $group on the common key that is required and keep the $last or $first depending on sort order occurrences from the grouping boundary for the properties that are required.



Also for BSON Dates as opposed to a timestamp value as in the question, see Group result by 15 minutes time interval in MongoDb for different approaches on how to accumulate for different time intervals actually using and returning BSON Date values.




Not quite sure what you are going for here but you could do this in aggregate if my understanding is right. So to get the last record for each day:



db.collection.aggregate([
// Sort in date order as ascending
"$sort": "date": 1 ,

// Date math converts to whole day
"$project":
"adco": 1,
"hchc": 1,
"hchp": 1,
"hhphc": 1,
"ptec": 1,
"iinst": 1,
"papp": 1,
"imax": 1,
"optarif": 1,
"isousc": 1,
"motdetat": 1,
"date": 1,
"wholeDay": "$subtract": ["$date","$mod": ["$date",86400000]]
,

// Group on wholeDay ( _id insertion is monotonic )
"$group":
"_id": "$wholeDay",
"docId": "$last": "$_id" ,
"adco": "$last": "$adco" ,
"hchc": "$last": "$hchc" ,
"hchp": "$last": "$hchp" ,
"hhphc": "$last": "$hhphc" ,
"ptec": "$last": "$ptec" ,
"iinst": "$last": "$iinst" ,
"papp": "$last": "$papp" ,
"imax": "$last": "$imax" ,
"optarif": "$last": "$optarif",
"isousc": "$last": "$isouc" ,
"motdetat": "$last": "$motdetat" ,
"date": "$last": "$date" ,

])


So the principle here is that given the timestamp value, do the date math to project that as the midnight time at the beginning of each day. Then as the _id key on the document is already monotonic (always increasing), then simply group on the wholeDay value while pulling the $last document from the grouping boundary.



If you don't need all the fields then only project and group on the ones you want.



And yes you can do this in the spring data framework. I'm sure there is a wrapped command in there. But otherwise, the incantation to get to the native command goes something like this:



mongoOps.getCollection("yourCollection").aggregate( ... )


For the record, if you actually had BSON date types rather than a timestamp as a number, then you can skip the date math:



db.collection.aggregate([
"$group":
"_id":
"year": "$year": "$date" ,
"month": "$month": "$date" ,
"day": "$dayOfMonth": "$date"
,
"hchp": "$last": "$hchp"

])





share|improve this answer
























    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%2f22202938%2ffind-last-record-of-each-day%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









    3














    A bit more modern than the original answer:



    db.collection.aggregate([
    "$sort": "date": 1 ,
    "$group":
    "_id":
    "$subtract": ["$date","$mod": ["$date",86400000]]
    ,
    "doc": "$last": "$$ROOT"
    ,
    "$replaceRoot": "newDocument": "$doc"
    ])


    The same principle applies that you essentially $sort the collection and then $group on the required grouping key picking up the $last data from the grouping boundary.



    Making things a bit clearer since the original writing is that you can use $$ROOT instead of specifying every document property, and of course the $replaceRoot stage allows you to restore that data fully as the original document form.



    But the general solution is still $sort first, then $group on the common key that is required and keep the $last or $first depending on sort order occurrences from the grouping boundary for the properties that are required.



    Also for BSON Dates as opposed to a timestamp value as in the question, see Group result by 15 minutes time interval in MongoDb for different approaches on how to accumulate for different time intervals actually using and returning BSON Date values.




    Not quite sure what you are going for here but you could do this in aggregate if my understanding is right. So to get the last record for each day:



    db.collection.aggregate([
    // Sort in date order as ascending
    "$sort": "date": 1 ,

    // Date math converts to whole day
    "$project":
    "adco": 1,
    "hchc": 1,
    "hchp": 1,
    "hhphc": 1,
    "ptec": 1,
    "iinst": 1,
    "papp": 1,
    "imax": 1,
    "optarif": 1,
    "isousc": 1,
    "motdetat": 1,
    "date": 1,
    "wholeDay": "$subtract": ["$date","$mod": ["$date",86400000]]
    ,

    // Group on wholeDay ( _id insertion is monotonic )
    "$group":
    "_id": "$wholeDay",
    "docId": "$last": "$_id" ,
    "adco": "$last": "$adco" ,
    "hchc": "$last": "$hchc" ,
    "hchp": "$last": "$hchp" ,
    "hhphc": "$last": "$hhphc" ,
    "ptec": "$last": "$ptec" ,
    "iinst": "$last": "$iinst" ,
    "papp": "$last": "$papp" ,
    "imax": "$last": "$imax" ,
    "optarif": "$last": "$optarif",
    "isousc": "$last": "$isouc" ,
    "motdetat": "$last": "$motdetat" ,
    "date": "$last": "$date" ,

    ])


    So the principle here is that given the timestamp value, do the date math to project that as the midnight time at the beginning of each day. Then as the _id key on the document is already monotonic (always increasing), then simply group on the wholeDay value while pulling the $last document from the grouping boundary.



    If you don't need all the fields then only project and group on the ones you want.



    And yes you can do this in the spring data framework. I'm sure there is a wrapped command in there. But otherwise, the incantation to get to the native command goes something like this:



    mongoOps.getCollection("yourCollection").aggregate( ... )


    For the record, if you actually had BSON date types rather than a timestamp as a number, then you can skip the date math:



    db.collection.aggregate([
    "$group":
    "_id":
    "year": "$year": "$date" ,
    "month": "$month": "$date" ,
    "day": "$dayOfMonth": "$date"
    ,
    "hchp": "$last": "$hchp"

    ])





    share|improve this answer





























      3














      A bit more modern than the original answer:



      db.collection.aggregate([
      "$sort": "date": 1 ,
      "$group":
      "_id":
      "$subtract": ["$date","$mod": ["$date",86400000]]
      ,
      "doc": "$last": "$$ROOT"
      ,
      "$replaceRoot": "newDocument": "$doc"
      ])


      The same principle applies that you essentially $sort the collection and then $group on the required grouping key picking up the $last data from the grouping boundary.



      Making things a bit clearer since the original writing is that you can use $$ROOT instead of specifying every document property, and of course the $replaceRoot stage allows you to restore that data fully as the original document form.



      But the general solution is still $sort first, then $group on the common key that is required and keep the $last or $first depending on sort order occurrences from the grouping boundary for the properties that are required.



      Also for BSON Dates as opposed to a timestamp value as in the question, see Group result by 15 minutes time interval in MongoDb for different approaches on how to accumulate for different time intervals actually using and returning BSON Date values.




      Not quite sure what you are going for here but you could do this in aggregate if my understanding is right. So to get the last record for each day:



      db.collection.aggregate([
      // Sort in date order as ascending
      "$sort": "date": 1 ,

      // Date math converts to whole day
      "$project":
      "adco": 1,
      "hchc": 1,
      "hchp": 1,
      "hhphc": 1,
      "ptec": 1,
      "iinst": 1,
      "papp": 1,
      "imax": 1,
      "optarif": 1,
      "isousc": 1,
      "motdetat": 1,
      "date": 1,
      "wholeDay": "$subtract": ["$date","$mod": ["$date",86400000]]
      ,

      // Group on wholeDay ( _id insertion is monotonic )
      "$group":
      "_id": "$wholeDay",
      "docId": "$last": "$_id" ,
      "adco": "$last": "$adco" ,
      "hchc": "$last": "$hchc" ,
      "hchp": "$last": "$hchp" ,
      "hhphc": "$last": "$hhphc" ,
      "ptec": "$last": "$ptec" ,
      "iinst": "$last": "$iinst" ,
      "papp": "$last": "$papp" ,
      "imax": "$last": "$imax" ,
      "optarif": "$last": "$optarif",
      "isousc": "$last": "$isouc" ,
      "motdetat": "$last": "$motdetat" ,
      "date": "$last": "$date" ,

      ])


      So the principle here is that given the timestamp value, do the date math to project that as the midnight time at the beginning of each day. Then as the _id key on the document is already monotonic (always increasing), then simply group on the wholeDay value while pulling the $last document from the grouping boundary.



      If you don't need all the fields then only project and group on the ones you want.



      And yes you can do this in the spring data framework. I'm sure there is a wrapped command in there. But otherwise, the incantation to get to the native command goes something like this:



      mongoOps.getCollection("yourCollection").aggregate( ... )


      For the record, if you actually had BSON date types rather than a timestamp as a number, then you can skip the date math:



      db.collection.aggregate([
      "$group":
      "_id":
      "year": "$year": "$date" ,
      "month": "$month": "$date" ,
      "day": "$dayOfMonth": "$date"
      ,
      "hchp": "$last": "$hchp"

      ])





      share|improve this answer



























        3












        3








        3







        A bit more modern than the original answer:



        db.collection.aggregate([
        "$sort": "date": 1 ,
        "$group":
        "_id":
        "$subtract": ["$date","$mod": ["$date",86400000]]
        ,
        "doc": "$last": "$$ROOT"
        ,
        "$replaceRoot": "newDocument": "$doc"
        ])


        The same principle applies that you essentially $sort the collection and then $group on the required grouping key picking up the $last data from the grouping boundary.



        Making things a bit clearer since the original writing is that you can use $$ROOT instead of specifying every document property, and of course the $replaceRoot stage allows you to restore that data fully as the original document form.



        But the general solution is still $sort first, then $group on the common key that is required and keep the $last or $first depending on sort order occurrences from the grouping boundary for the properties that are required.



        Also for BSON Dates as opposed to a timestamp value as in the question, see Group result by 15 minutes time interval in MongoDb for different approaches on how to accumulate for different time intervals actually using and returning BSON Date values.




        Not quite sure what you are going for here but you could do this in aggregate if my understanding is right. So to get the last record for each day:



        db.collection.aggregate([
        // Sort in date order as ascending
        "$sort": "date": 1 ,

        // Date math converts to whole day
        "$project":
        "adco": 1,
        "hchc": 1,
        "hchp": 1,
        "hhphc": 1,
        "ptec": 1,
        "iinst": 1,
        "papp": 1,
        "imax": 1,
        "optarif": 1,
        "isousc": 1,
        "motdetat": 1,
        "date": 1,
        "wholeDay": "$subtract": ["$date","$mod": ["$date",86400000]]
        ,

        // Group on wholeDay ( _id insertion is monotonic )
        "$group":
        "_id": "$wholeDay",
        "docId": "$last": "$_id" ,
        "adco": "$last": "$adco" ,
        "hchc": "$last": "$hchc" ,
        "hchp": "$last": "$hchp" ,
        "hhphc": "$last": "$hhphc" ,
        "ptec": "$last": "$ptec" ,
        "iinst": "$last": "$iinst" ,
        "papp": "$last": "$papp" ,
        "imax": "$last": "$imax" ,
        "optarif": "$last": "$optarif",
        "isousc": "$last": "$isouc" ,
        "motdetat": "$last": "$motdetat" ,
        "date": "$last": "$date" ,

        ])


        So the principle here is that given the timestamp value, do the date math to project that as the midnight time at the beginning of each day. Then as the _id key on the document is already monotonic (always increasing), then simply group on the wholeDay value while pulling the $last document from the grouping boundary.



        If you don't need all the fields then only project and group on the ones you want.



        And yes you can do this in the spring data framework. I'm sure there is a wrapped command in there. But otherwise, the incantation to get to the native command goes something like this:



        mongoOps.getCollection("yourCollection").aggregate( ... )


        For the record, if you actually had BSON date types rather than a timestamp as a number, then you can skip the date math:



        db.collection.aggregate([
        "$group":
        "_id":
        "year": "$year": "$date" ,
        "month": "$month": "$date" ,
        "day": "$dayOfMonth": "$date"
        ,
        "hchp": "$last": "$hchp"

        ])





        share|improve this answer















        A bit more modern than the original answer:



        db.collection.aggregate([
        "$sort": "date": 1 ,
        "$group":
        "_id":
        "$subtract": ["$date","$mod": ["$date",86400000]]
        ,
        "doc": "$last": "$$ROOT"
        ,
        "$replaceRoot": "newDocument": "$doc"
        ])


        The same principle applies that you essentially $sort the collection and then $group on the required grouping key picking up the $last data from the grouping boundary.



        Making things a bit clearer since the original writing is that you can use $$ROOT instead of specifying every document property, and of course the $replaceRoot stage allows you to restore that data fully as the original document form.



        But the general solution is still $sort first, then $group on the common key that is required and keep the $last or $first depending on sort order occurrences from the grouping boundary for the properties that are required.



        Also for BSON Dates as opposed to a timestamp value as in the question, see Group result by 15 minutes time interval in MongoDb for different approaches on how to accumulate for different time intervals actually using and returning BSON Date values.




        Not quite sure what you are going for here but you could do this in aggregate if my understanding is right. So to get the last record for each day:



        db.collection.aggregate([
        // Sort in date order as ascending
        "$sort": "date": 1 ,

        // Date math converts to whole day
        "$project":
        "adco": 1,
        "hchc": 1,
        "hchp": 1,
        "hhphc": 1,
        "ptec": 1,
        "iinst": 1,
        "papp": 1,
        "imax": 1,
        "optarif": 1,
        "isousc": 1,
        "motdetat": 1,
        "date": 1,
        "wholeDay": "$subtract": ["$date","$mod": ["$date",86400000]]
        ,

        // Group on wholeDay ( _id insertion is monotonic )
        "$group":
        "_id": "$wholeDay",
        "docId": "$last": "$_id" ,
        "adco": "$last": "$adco" ,
        "hchc": "$last": "$hchc" ,
        "hchp": "$last": "$hchp" ,
        "hhphc": "$last": "$hhphc" ,
        "ptec": "$last": "$ptec" ,
        "iinst": "$last": "$iinst" ,
        "papp": "$last": "$papp" ,
        "imax": "$last": "$imax" ,
        "optarif": "$last": "$optarif",
        "isousc": "$last": "$isouc" ,
        "motdetat": "$last": "$motdetat" ,
        "date": "$last": "$date" ,

        ])


        So the principle here is that given the timestamp value, do the date math to project that as the midnight time at the beginning of each day. Then as the _id key on the document is already monotonic (always increasing), then simply group on the wholeDay value while pulling the $last document from the grouping boundary.



        If you don't need all the fields then only project and group on the ones you want.



        And yes you can do this in the spring data framework. I'm sure there is a wrapped command in there. But otherwise, the incantation to get to the native command goes something like this:



        mongoOps.getCollection("yourCollection").aggregate( ... )


        For the record, if you actually had BSON date types rather than a timestamp as a number, then you can skip the date math:



        db.collection.aggregate([
        "$group":
        "_id":
        "year": "$year": "$date" ,
        "month": "$month": "$date" ,
        "day": "$dayOfMonth": "$date"
        ,
        "hchp": "$last": "$hchp"

        ])






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 5 '18 at 3:48

























        answered Mar 6 '14 at 5:51









        Neil LunnNeil Lunn

        105k24 gold badges194 silver badges198 bronze badges




        105k24 gold badges194 silver badges198 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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%2f22202938%2ffind-last-record-of-each-day%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현