Sensor sends packets in a 15-30 second interval which is stored in the mongodb collection.
Now I have to do calculation for which I need to take out the difference between each such consecutive data packets time difference,
How can I find the difference between each consecutive packet time difference
Please provide sample documents in JSON format so that we can cut-n-paste directly into our system.
Please define how a packet is consecutive one or it is related to something else. For example, do you have packets from multiple devices in the same collection.
If this is a frequent use-case you might want to consider storing the time of the previous or next packet or the time interval permanently when you insert a new packet. Finding the time interval or the time of the previous / next packet will probably involve $lookup, so you either do it once at insertion time or every time you run the query.
Sorry for not making it more clear
the doc will look like
power:on // this can be either on or off
Now the packets come every 15-30 sec, and I need the difference of every consecutive document timestamp for lets say 1 day.
For a day there will be 2000-3000 documents and I need time difference for every consecutive document, time difference calculated using timestamp