Solution Timeline

All versions (edits) of solutions to Mongodb query help (spatial query) appear below in the order they were created. Comments that appear under revisions were those created when that particular revision was current.

To see the revision history of a single solution (with diffs), click on the solution number (ie. "#1") in the upper right corner of a solution revision below.

← Bounty Expand all edits

Hello, just create date, last date, format them and look for gte lte in that dates range.
works in mongodb shell.

https://docs.mongodb.org/manual/reference/operator/query/gte/

var nowDate = new Date(2015,01,01);
lastDate = new Date();
lastDate.setDate(nowDate.getDate()+5);
db.test.find({"dates.startDate":{$gte: Number(nowDate.toLocaleFormat("%Y%m%d%H%M")), $lte:Number(lastDate.toLocaleFormat("%Y%m%d%H%M"))} })

Here you go:

var sinceDate = new Date(),
    untilDate = new Date();

untilDate.setDate(untilDate.getDate() + 5);

db.collection.find({
    "dates.startDate": { $lt: Number(untilDate.toLocaleFormat("%Y%m%d%H%M") },
    "dates.endDate"  : { $gt: Number(sinceDate.toLocaleFormat("%Y%m%d%H%M") }
});

Here you go:

var sinceDate = new Date(),
    untilDate = new Date();

untilDate.setDate(untilDate.getDate() + 5);

db.collection.find({
    "dates.startDate": { $lt: formatDate(untilDate) },
    "dates.endDate"  : { $gt: formatDate(sinceDate) }
});

function formatDate (date) {
    return date.getFullYear().toString() 
         + ('0' + (date.getMonth() + 1)).slice(-2) 
         + ('0' + date.getDay()).slice(-2)
         + ('0' + date.getHours()).slice(-2)
         + ('0' + date.getMinutes()).slice(-2);
}

Here you go:

var sinceDate = new Date(),
    untilDate = new Date();

untilDate.setDate(untilDate.getDate() + 5);

function formatDate (date) {
    return parseInt(
             date.getFullYear().toString() 
             + ('0' + (date.getMonth() + 1)).slice(-2) 
             + ('0' + date.getDate()).slice(-2)
             + ('0' + date.getHours()).slice(-2)
             + ('0' + date.getMinutes()).slice(-2)
           );
}

db.collection.find({
    "dates.startDate": { $lt: formatDate(untilDate) },
    "dates.endDate"  : { $gt: formatDate(sinceDate) }
});
Winning solution