MongoDB offers various methods for counting the documents in a collection or view. There are also some aggregation operators that enable you to count incoming documents from a previous aggregation pipeline stage.
Continue readingMongoDB $sampleRate
In MongoDB, the $sampleRate
aggregation pipeline stage matches a random selection of input documents.
The number of documents selected approximates the sample rate expressed as a percentage of the total number of documents.
The $sampleRate
operator was introduced in MongoDB 4.4.2.
MongoDB $reverseArray
In MongoDB, the $reverseArray
aggregation pipeline operator reverses the order of items in an array.
It accepts an array expression as an argument and returns an array with the elements in reverse order.
Continue readingFind Out the Data Type of the Columns Returned in a Result Set in SQL Server
In SQL Server, there are a few ways to get metadata of the result set from a query. This includes the data type of the columns returned by a T-SQL query.
In particular, the sys.dm_exec_describe_first_result_set
system dynamic management function is a good choice for such a task.
MongoDB $range
In MongoDB, the $range
aggregation pipeline operator returns a generated sequence of numbers in an array.
This sequence of numbers is based on the input values you provide.
Continue readingMongoDB $round
In MongoDB, the $round
aggregation pipeline operator rounds a number to a whole integer or to a specified decimal place.
You have the option of specifying how many decimal places for which to round the number. To do this, pass a second argument. The first argument is the number to round, and the second (optional) argument is the number of decimal places to round it to.
Continue readingImport Documents into MongoDB from an Array of JSON Documents
When using mongoimport
, you can use the --jsonArray
parameter to import an array of JSON documents.
Find Out if a Query uses an Index in MongoDB
In MongoDB, you can use the cursor.explain()
method or the db.collection.explain()
method to determine whether or not a query uses an index.
These methods enable you to view the query plan for the query, which includes whether or not it uses an index.
Continue readingMongoDB $sample
In MongoDB, the $sample
aggregation pipeline stage randomly selects the specified number of documents from its input.
MongoDB $rand
In MongoDB, the $rand
aggregation pipeline operator returns a random float between 0 and 1.
The floating point value has up to 17 digits after the decimal point. Any trailing zeros are dropped, so the number of digits may vary.
The $rand
operator was introduced in MongoDB 4.4.2.