Reputation: 3043
I am working on meteor and i have this small problem.I'm sure many of you know the answer.
I'm using mongodb
I want posts which are posted from last month same date to till know
like
today 3 march
i want posts which are posted from
feb 3 to march 3
i inserted a date field in document like this
var dat=new Date();
Can we do it using Date field or do we need to store any other fields.
How to achieve it i have no ideas.
Thx in advance
Upvotes: 0
Views: 73
Reputation: 4882
According the official mongodb documentation, you can try this:
var end = new Date(); // today
var start = new Date().setMonth(end.getMonth() - 1); // last month
db.posts.find({created_on: {$gte: start, $lt: end}});
Upvotes: 1