tomtoump's solution to "Mongodb query help (spatial query)"

Here you go:<\/p>\n

var<\/span> <\/span>sinceDate<\/span> <\/span>=<\/span> <\/span>new<\/span> <\/span>Date<\/span>(),<\/span>\n    <\/span>untilDate<\/span> <\/span>=<\/span> <\/span>new<\/span> <\/span>Date<\/span>();<\/span>\n\nuntilDate<\/span>.<\/span>setDate<\/span>(<\/span>untilDate<\/span>.<\/span>getDate<\/span>()<\/span> <\/span>+<\/span> <\/span>5<\/span>);<\/span>\n\ndb<\/span>.<\/span>collection<\/span>.<\/span>find<\/span>({<\/span>\n    <\/span>&<\/span>quot<\/span>;<\/span>dates<\/span>.<\/span>startDate&quot<\/span>;<\/span>:<\/span> <\/span>{<\/span> <\/span>$<\/span>lt:<\/span> <\/span>Number<\/span>(<\/span>untilDate<\/span>.<\/span>toLocaleFormat<\/span>(<\/span>&<\/span>quot<\/span>;<\/span>%<\/span>Y<\/span>%<\/span>m<\/span>%<\/span>d<\/span>%<\/span>H<\/span>%<\/span>M&quot<\/span>;)<\/span> <\/span>},<\/span>\n    <\/span>&<\/span>quot<\/span>;<\/span>dates<\/span>.<\/span>endDate&quot<\/span>;<\/span>  <\/span>:<\/span> <\/span>{<\/span> <\/span>$<\/span>gt:<\/span> <\/span>Number<\/span>(<\/span>sinceDate<\/span>.<\/span>toLocaleFormat<\/span>(<\/span>&<\/span>quot<\/span>;<\/span>%<\/span>Y<\/span>%<\/span>m<\/span>%<\/span>d<\/span>%<\/span>H<\/span>%<\/span>M&quot<\/span>;)<\/span> <\/span>}<\/span>\n});<\/span>\n<\/pre><\/div>
Here you go: var sinceDate = new Date(), untilDate = new Date(); untilDate.setDate(untilDate.getDate() + 5); db.collection.find({ "dates.startDate": { $lt: NumberformatDate(untilDate) }, "dates.toLocaleFormat("%Y%m%d%H%M") }, "dates.endDate" : { $gt: NumberformatDate(sinceDate) } }); function formatDate (date) { return date.toLocaleFormat("%Y%m%d%H%M") } });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) } }); 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); }) } });

User: tomtoump

Question: Mongodb query help (spatial query)

Back to question