0

I have collection Ticket_master,which like as follows

Ticket_master

{
   _id:5e70ed53de0f7507d4da8dc2,
   "TICKET_NO" : 1000,
   "SUBJECT" : "Sub1",
   "DESCRIPTION" : "Desc1",
   "createdAt" : ISODate("2020-03-17T15:31:31.039Z"),
}

Already tried with the following code snippet and it returns null result set.

db.getCollection('ticket_masters').find({ 'createdAt':ISODate('2020-03-17T00:00:00.000Z')})

How fetch fetch data from ticket_master collection by matching the value with date of creation column,which is represented as createdAt.

Following code snippets return the results. Because it contain both date and time.How fetch data from the collection only with Date .

db.getCollection('ticket_masters').find({ 'createdAt':ISODate('2020-03-17T15:31:31.039+00:00')})
Sufail Kalathil
  • 558
  • 6
  • 21
  • Possible duplicated from https://stackoverflow.com/questions/8136652/query-mongodb-on-month-day-year-of-a-datetime – Alexandre Juma Apr 20 '20 at 21:02
  • Does this answer your question? [Query Mongodb on month, day, year... of a datetime](https://stackoverflow.com/questions/8136652/query-mongodb-on-month-day-year-of-a-datetime) – Alexandre Juma Apr 20 '20 at 21:03

1 Answers1

0

as long as you are searching for all the tickets that have been created on some day, so you can use a date range to filter the tickets

db.getCollection('ticket_masters').find({ 
    createdAt : { 
        $gte: ISODate('2020-03-17T00:00:00.000Z'), 
        $lt: ISODate('2020-03-18T00:00:00.000Z') 
    } 
})

this should return all the tickets that have been created on 17/03/2020

check this Mongo Playground

Mohammed Yousry
  • 2,134
  • 1
  • 5
  • 7