1

Im sending temperature data with timestamp into MongoDB. My document structure looks like this:

{
      "_id": ObjectId("57c974d705578f617f5491e3"),         
      "temperature" : 24,
      "timestamp" : "9/2/2016, 2:47:19 PM",
      "_msgid" : "7944eab7.86bb14"
}

and I want to get to freeboard the latest value of temperature via RESTHeart query. Was looking throught the documentation on restheart.org but with no result... How would the query look like? Any ideas? Thanks for replys...

Michal Janošec
  • 71
  • 1
  • 10

1 Answers1

1

If the _id is autogenerated then the last value is always the first returned from GET /db/coll.

This is because Restheart sort result by _id descending by default and the _id contains date and time in the most significant bytes.

So GET /db/coll?pagesize=1 does the trick.

If you want to sort by your timestamp field I see a problem since it is a string (not actually a date field) with a format that does not allow to sort by it lexicographically (such as for instance "2016-08-04-1839")

Andrea Di Cesare
  • 1,125
  • 6
  • 11
  • Thanks for your answer, I have reedited the timestamp format, cause I ran into the problem as you described today :D, also thanks for the info about _id sorting by default... very usefull :) – Michal Janošec Sep 07 '16 at 13:10