MongoDB $strLenCP

MongoDB, the $strLenCP aggregation pipeline operator returns the number of UTF-8 code points in the specified string.

The $strLenCP operator is different to the $strLenBytes operator, which returns the number of bytes in the string.

Read more

MongoDB $strLenBytes

MongoDB, the $strLenBytes aggregation pipeline operator returns the number of UTF-8 encoded bytes in the specified string.

Each character in a string can contain contain a different number of bytes, depending on the character being used. The $strLenBytes operator can figure out how many bytes each character contains and return the correct result for the whole string.

Read more

MongoDB $stdDevPop

In MongoDB, the $stdDevPop aggregation pipeline operator calculates the population standard deviation of its input values. 

The input values can be from a group of documents (i.e. documents that are grouped by the same key), or they can be multiple fields within a single document.

Read more

MongoDB $stdDevSamp

In MongoDB, the $stdDevSamp aggregation pipeline operator calculates the sample standard deviation of the input values.

The input values can be from a group of documents (i.e. documents that are grouped by the same key), or they can be multiple fields within a single document.

Read more

MongoDB $strcasecmp

In MongoDB, the $strcasecmp aggregation pipeline operator performs a case-insensitive comparison of two strings.

It returns either 1, 0, or -1, depending on whether or not the first string is greater than, equal to, or less than the second string.

Read more

How to Delete MongoDB Documents by Importing a File

As of mongoimport version 100.0.0, you can delete documents in MongoDB based on an imported file. To do this, use delete mode.

When you use delete mode, if an imported document has the same _id value as an existing one in the collection that you’re importing into, the existing document will be deleted.

You can also specify another field or fields (other than the _id field) to be the matching field if required.

Read more

MongoDB $split

In MongoDB, the $split aggregation pipeline operator divides a string into an array of substrings based on a delimiter.

The delimiter is removed from the string, and the substrings are added as elements to the array.

To use $split, you specify the string and the delimiter.

If the delimiter isn’t found in the string, the original string is returned as the only item in the array.

Read more

MongoDB $slice

In MongoDB, the $slice aggregation pipeline operator returns a subset of an array.

To use $slice, you specify the number of elements to return from the array. You can also specify a starting position for which to take the subset from the array.

Read more

2 Ways to Limit the Documents Returned in MongoDB

When you run queries In MongoDB, you have the option of limiting the documents returned. This is where you specify a maximum number of documents to be returned by the operation.

For example, if an operation would normally return 2,000 documents, but you specify a limit of 1,000, then only 1,000 documents are returned. However, if the operation would only return say, 500 documents, then all 500 are returned (because they don’t breach the 1,000 document limit).

This is a bit like using the TOP clause in SQL Server, or the LIMIT clause in MySQL, MariaDB, PostgreSQL, and SQLite.

Read more