I want query something based on date(11/11/2016)
using like
operator:
How to do the same in mongodb?
db.getCollection('TableName').find({"Date":/.*10/11/2016.*/})
I tried with this query but getting invalid result
.
I want query something based on date(11/11/2016)
using like
operator:
How to do the same in mongodb?
db.getCollection('TableName').find({"Date":/.*10/11/2016.*/})
I tried with this query but getting invalid result
.
There is no like
in mongo,You can use regex
Here in this case you dont require regex,you can get your result using simple find query,Date stored in mongodb is in ISO
formate,So first convert your date to ISO date
and then find for eg
var convertDate = "11/11/2016";
convertDate = new Date(11/11/2016);
db.getCollection('TableName').find({date : convertDate})
Or if you want like
in mongo use this
1)Search directly
db.getCollection('TableName').find({date : {$regex : "11/11/2016"}})
2) Create a text index on date and then search
db.getCollection('TableName').find({$text:{$search:"11/11/2016"}})
Like/Regex in Mongodb can be done by .
when you have /
in value.
To get date starting with 10/11/
, try this for your query:
db.getCollection('TableName').find({'Date':/^10.11./})