difference between dates mongodb code example

Example 1: mongodb date before 2 days

// 2 days before
"StartDate" : { "$lt" : new Date(ISODate().getTime() - 1000 * 86400 * 2) }

Example 2: mongodb date before 2 days

query = {
    timestamp: { // 18 minutes ago (from now)
        $gt: new Date(ISODate().getTime() - 1000 * 60 * 18)
    }
}

Example 3: difference between dates mongodb

db.sales.aggregate( [ { $project: { item: 1, dateDifference: { $subtract: [ "$$NOW", "$date" ] } } } ] )

Example 4: mongodb subtract dates

db.sales.aggregate( [ { $project: { item: 1, total: { $subtract: [ { $add: [ "$price", "$fee" ] }, "$discount" ] } } } ] )