The following table contains a list of whitespace characters that MongoDB removes by default when using the $trim
, $ltrim
, and $rtrim
aggregation pipeline operators.
MongoDB $toLong
From MongoDB 4.0, you can use the $toLong
aggregation pipeline operator to convert a value to a long.
MongoDB $toInt
From MongoDB 4.0, you can use the $toInt
aggregation pipeline operator to convert a value to an integer.
MongoDB $toDouble
From MongoDB 4.0, you can use the $toDouble
aggregation pipeline operator to convert a value to a double.
MongoDB $toDecimal
From MongoDB 4.0, you can use the $toDecimal
aggregation pipeline operator to convert a value to a decimal.
MongoDB $toBool
From MongoDB 4.0, you can use the $toBool
aggregation pipeline operator to convert a value to a boolean.
MongoDB $toString
From MongoDB 4.0, you can use the $toString
aggregation pipeline operator to convert a value to a string.
MongoDB $convert
In MongoDB, you can use the $convert
aggregation pipeline operator to convert a value to a specified type.
You can convert any valid expression to a double, string, ObjectId, boolean, Date, integer, long, or decimal.
Continue readingMongoDB Date() Method
In MongoDB, the Date()
method returns a date either as a string or as a Date object.
- When you call it as
Date()
, it returns the current date as a string in themongo
shell. - When you call it as
new Date()
, it returns the current date as a Date object.
You can also provide a specific date as an argument to new Date()
, so that it uses that date.
MongoDB NOW Aggregation Variable
MongoDB provides the NOW
system variable that allows you to get the current datetime value when using an aggregation pipeline.
This can be useful for when you want to update a document with the current datetime.
Continue reading