我想根据日期而不是实际输入集合的日期时间从集合中提取数据我需要像在MySQL中那样做
i.e select * from customer as c where DATE(c.curr_date)="2018-03-10 10:43:23"
我希望以上查询在mongodb中实现。
提前致谢
答案 0 :(得分:0)
var jsonendDate = date.getFullYear()+"-"+("0" + (date.getMonth() + 1)).slice(-2)+"-"+("0" + date.getDate()).slice(-2)+"T23:59:00.123Z";
var jsonstartDate = date.getFullYear()+"-"+("0" + (date.getMonth() + 1)).slice(-2)+"-"+("0" + date.getDate()).slice(-2)+"T00:00:00.123Z";
jsonendDate = new Date(jsonendDate);
jsonstartDate = new Date(jsonstartDate);
db.collection.find({"created_at":{$gte:jsonstartDate,$lte:jsonendDate}},function(err,data){
console.log(data);
})