0

I want to find a document using the date field contained in the collection

//Document Exemple: MODEL : MY_EVENT

event_time_produce: '2018-01-03T11:00:00.201Z',
event_name : 'show'

I would like to find all the documents starting with '2018-01-03T11:00:'

I want to ignore the part of Millesecobde & ISOtype ..etc

Like in SQL :

SELECT * from MY_EVENT where event_time_produce LIKE '2018-01-03T11:00:%'

I have tried this but not working ( Mongoose)

MY_EVENT.find({event_time_produce : {
                        $regex: new RegExp('^2018-01-03T11:00:00.*$')
                    }})
         .exec(....)

Simple search work :

MY_EVENT.find({event_time_produce : '2018-01-03T11:00:00.201Z'})
         .exec(....) 

but I want to get all the documents from 03 Janury 2018 at 11:00:XX

no matter the second just verify the date, hours & minute.

Anis Mokeddes
  • 61
  • 1
  • 9

1 Answers1

2

Isn't it an issue on your regular expression?

On your example for SQL you have 2018-01-03T11:00:% When on mongo you got ^2018-01-03T11:00:00.*$ (2 additional zeros after 11:00:)

Update: If your data on the actual document is ISODate instead of a regular string, better to use ranges like this: {event_time_produce:{$gte:ISODate("2018-01-03T11:00:00.000+0000"),$lte:ISODate("2018-01-03T11:00:59.999+0000") }}