Below are the steps that I used to install Redis on my M1 Mac. The M1 Mac (and M2) uses the ARM64 architecture, but this is not a problem, as Redis versions 4.0 and above support the ARM architecture.
Continue readingCategory: NoSQL
3 Ways to Convert a String to a Date in MongoDB
If you have a MongoDB collection with dates stored as strings, you can convert those into the Date BSON type if required.
Below are three ways to convert a string into a Date in MongoDB.
Continue readingRemove Duplicates when using $unionWith in MongoDB
In MongoDB, the $unionWith
aggregation pipeline stage performs a union of two collections, and it includes duplicates.
This behaves in a similar way to SQL’s UNION ALL
, which also includes duplicates. By contrast, using just UNION
(i.e. without the ALL
)in SQL removes duplicates.
In MongoDB, we don’t have the option of specifying $unionWith ALL
or similar, so we need to reduce duplicates in another way.
In MongoDB, we can remove duplicates by using the $group
stage.
3 Ways to Return a Random Sample of Documents from a MongoDB Collection
If you need to return a small sample of random documents from a collection, here are three approaches you can try using the aggregation pipeline.
Continue readingMongoDB Aggregation Operators for Returning Date Parts
This article lists the various aggregation pipeline operators that can be used to return individual date parts from a Date object in MongoDB.
Continue reading2 Ways to Unhide an Index in MongoDB
If you have a hidden index in MongoDB, you can use the unhideIndex()
method or the collMod
administration command to unhide it.
MongoDB $round vs $trunc: What’s the Difference?
MongoDB’s aggregation pipeline framework includes a $round
operator and a $trunc
operator. These operators perform similar, but different tasks.
$strLenBytes vs $strLenCP in MongoDB: What’s the Difference?
MongoDB includes the $strLenBytes
and $strLenCP
operators in its aggregation pipeline framework. These operators do a similar but slightly different thing. In some cases, both will return exactly the same result, while in other cases the results will differ.
Here’s a quick overview of the difference between these two operators.
Continue reading2 Ways to Get a Document’s Size in MongoDB
If you need to return the size of a document in MongoDB, you can use the following:
- The
$bsonSize
aggregation pipeline operator - The
Object.bsonSize()
method
Below are examples of each approach.
Continue reading3 Ways to Sort Documents in MongoDB
MongoDB provides a few ways to sort documents in a particular order. Each of these allow us to order the documents in ascending or descending order.
There’s also the option to order the results of a $text
search – sorting by the computed textScore
metadata in descending order.
Here are 3 ways to sort documents in MongoDB.
Continue reading