5 Ways to Get the Month from a Date in MongoDB

MongoDB provides a number of aggregation pipeline operators for working with dates, including operators that extract certain parts of dates, such as the year, month, day, etc.

There are also a couple of MongoDB methods that enable you to iterate through a cursor, and apply a JavaScript function. You can therefore use JavaScript to extract date values and date parts, etc from a field as required.

This article presents 5 ways to return the month portion from a date in MongoDB.

Read more

6 Ways to Get the Year from a Date in MongoDB

MongoDB provides quite a few aggregation pipeline operators for working with dates. This includes operators that extract certain parts of dates, such as the year, month, day, etc.

There are also a couple of MongoDB methods that enable you to iterate through a cursor, and apply a JavaScript function. This therefore allows you to use JavaScript to extract date values and date parts, etc from a field.

This article presents 6 ways to return the year portion from a date in MongoDB.

Read more

MongoDB $exists

In MongoDB, you can use the $exists element query operator to match documents that contain a specific field.

You can also use it to match documents that don’t contain a specific field.

You can also use it in conjunction with other operators such $nin to match documents where a given field exists, but it doesn’t contain a specific value.

Read more

MongoDB $replaceAll

The $replaceAll aggregation pipeline operator was introduced in MongoDB 4.4.

This operator replaces all instances of a search string in an input string with a replacement string and returns the result.

If the search string isn’t found, then $replaceAll returns the input string.

Read more