-1
I’m trying to perform a query on Mongodb where I have the list of users, with a date column indicating the last time the user went online. In this query, based on the date and time the user went online I would like to add a new column $addFields
with information whether the user is online, absent or offline.
My criteria would be something like this:
- If the last time the user went online was 1 minute ago, then it’s online.
- If the last time the user went online was 2 minutes ago, then he is away.
- If the last time the user went online was 3 minutes ago, then it’s offline.
My data structure is as follows:
{
_id: ObjectId('5ee191a8b3455000060c8296'),
nome: 'Fulano'
session_active: 2020-07-03T08:52:48.428+00:00
}
The result I was hoping for would be something like:
Server time: 08:52 am
{
_id: ObjectId('5ee191a8b3455000060c8296'),
nome: 'Fulano'
session_active: 2020-07-03T08:52:00.428+00:00,
status: 'Online'
}
Server time: 08:52 am
{
_id: ObjectId('5ee191a8b3455000060c8296'),
nome: 'Fulano'
session_active: 2020-07-03T08:53:00.428+00:00,
status: 'Ausente'
}
Server time: 08:52 am
{
_id: ObjectId('5ee191a8b3455000060c8296'),
nome: 'Fulano'
session_active: 2020-07-03T08:54:00.428+00:00,
status: 'Offline'
}
Luiz Felipe, thank you so much for your contribution. She was of total help and solved the problem in which I was looking for the solution.
– JGouveia