This question addressess generating a query from C#, but how does one generate a comparision value equivalent to GetDate() (SQL Server) in MongoDB
i.e. I would like to express a JSON query like this:
{
Expiration: {$lte: Now())},
}
ISODate() is a helper function that's built into to MongoDB and wraps the native JavaScript Date object. When you use the ISODate() constructor from the Mongo shell, it actually returns a JavaScript Date object.
$gte selects the documents where the value of the field is greater than or equal to (i.e. >= ) a specified value (e.g. value .) For most data types, comparison operators only perform comparisons on fields where the BSON type matches the query value's type.
Use the Javascript function new Date()
:
db.collection.find({ Expiration: { $lte: new Date() } })
The Mongo shell is just a Javascript shell, so you can, in principle, use any Javascript method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With