I have a collection of users and i want to get all the users who registered in 2015.
With a normal date string it is possible tot query:
$query=[
'timestamp'=> [
'$regex' => "2015"
]
];
But when I try this on a MongDate timestamp it doens't work anymore.
Any ideas?
A date stored in MongoDB is not a string, it's a date type. You cannot match regular expressions against it because it is not a string. Instead, just search with a date range (and index the date field, if you want it to be fast):
I'm not familiar with PHP so I wrote the query in mongo shell syntax.