Reputation: 49
I have below collection data in mongo db. "enddate" : ISODate("2019-03-27T14:30:00.000Z"), "date" : ISODate("2019-03-27T10:30:00.000Z"),
I have two date like start date "2019-03-26T19:30:00.000Z" and end date "2019-03-26T20:30:00.000Z"
I want to find above two date time period exits in collection or not. Please help to make mongodb query.
Upvotes: 0
Views: 67
Reputation: 49
advt.date = m.utc().toISOString();
advt.enddate = me.utc().toISOString();
advt.time = m.utc().toISOString();
advt.endtime = me.utc().toISOString();
var Query = Advertisement.find({
$or: [
{ $and:[{ date: { $gte: advt.date }, enddate:{ $lte: advt.enddate } }] } ,
{ $and:[{ enddate: { $gte: advt.date }, date:{ $lte: advt.enddate } }] }
],"ad_type":"splash", "isDeleted":false, "_id":{ $ne: advt._id }
});
Upvotes: 1
Reputation: 331
You can use ObjectId.getTimestamp()
for that purpose.
Also check this Link
Upvotes: 0