Fez Vrasta
Fez Vrasta

Reputation: 14815

load queries created into a specific time range with MongoDB

I need to store articles in my MongoDB and I'd need a way to load articles specifing the time range so I can load for example only the articles created between today and 7 days ago (2014-06-30 - 2014-06-23).

I think I first need to create a key with the timestamp but after that?

I've not found anything on Google and I'd like to have some suggestion. I'm using the native node.js driver

Upvotes: 0

Views: 27

Answers (1)

fmsf
fmsf

Reputation: 37137

Example taken from the website: http://cookbook.mongodb.org/patterns/date_range/

var start = new Date(2010, 3, 1);
var end = new Date(2010, 4, 1); 

db.posts.find({created_on: {$gte: start, $lt: end}});

Upvotes: 2

Related Questions