How to get all IDs from Mongo with no record in the past hour

Anton Swanevelder

Considering the following documents:

[{
    "imei": "352413080100000",
    "datestamp": "2019-03-25T19:17:11.471Z"
}]

How can I get a unique list of all imei where there is no record for the past hour?

Ashh

You can use $group aggregation to find the unique record for the imei field and use moment library to cut of the last hour from the current time.

db.collection.aggregate([
  { "$match": {
    "datestamp": {
      "$lte": moment().subtract(1, 'hours').toDate()
    }
  }},
  { "$group": {
    "_id": '$imei'
  }}
])

Or even you can use distinct query as well

const imeis = await db.collection.distinct('imei', { "datestamp": { "$lte": moment().subtract(1, 'hours').toDate() } })
console.log(imeis)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get the records from the past 1 hour in psql

How do I get results from past 1 hour in sql

How to get all IDs from div element?

How to get all records, where the date value in the record is older then an hour with Prisma DB and javascript?

get data for a record in the past

How to change a record for all IDs, JOIN and concatenate

How to get all of the collection ids from document on Firestore?

Python how do I get all ids from this api dictionary

How to get all node Ids from VIS.js network

How do I get all edge ids from a cluster

How to get the IDs of the all documents from the firebase using flutter web

How to get all of the IDs with jQuery?

How to get date of all days in past week?

How to get records from SQL Server for every hour only first record in a day in a month?

How to get a list of all months from current month to a month in the past using moment.js

how to get last week's data of all past years from a python dataframe?

How to get individuals all record in php from mysqli

How to get all values from combobox selected record?

How to get the average of a value for each hour in a specific day in Mongo?

Get records for past month, day and a specific 24 hour period in the past

How to get Images from Internet and past it in a ListView?

how to get results from Athena for the past week?

Powershell - how to get list of all jobs that had runs in the last hour From TASK Scheduler

How to get all live thread IDs in btrace?

How we get all ids of sibling div?

How to get the ids of all elements of a particular class?

How to get all used IDs in a log file

In Coredata, how to get all IDs for specific table?

how to get all post ids in wordpress