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.
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.
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.
If you’ve encountered error Msg 7411, Level 16 in SQL Server, it’s because you need to enable “RPC out” on the linked server that you’re trying to execute code on.
Continue readingIn MongoDB, the $size
aggregation pipeline operator counts and returns the total number of items in an array.
The $size
operator accepts one argument. The argument can be any valid expression that resolves to an array.
In MongoDB, if you need to delete a document in the mongo shell, you can use:
db.collection.remove()
methoddelete
commanddb.collection.deleteOne()
methoddb.collection.deleteMany()
methodThis article provides examples of each.
Continue readingIn MongoDB, the $setUnion
aggregation pipeline operator accepts two or more arrays and returns an array containing the elements that appear in any of those input arrays.
$setUnion
accepts two or more arguments, all of which can be any valid expression as long as they each resolve to an array. $setUnion
treats the arrays as sets.
In MongoDB, the $setIsSubset
aggregation pipeline operator accepts two arrays and returns true
when the first array is a subset of the second, and false
when it isn’t.
The first array is also considered a subset when it equals the second array.
Continue readingIn MongoDB, the $setIntersection
aggregation pipeline operator accepts two or more arrays and returns an array that contains the elements that appear in all input arrays.
$setIntersection
accepts two or more arguments, all of which can be any valid expression as long as they each resolve to an array. $setIntersection
treats the arrays as sets.
In MongoDB, the $setEquals
aggregation pipeline operator compares two or more arrays and returns true
 if they have the same distinct elements and false
 otherwise.
$setEquals
accepts two or more arguments, all of which can be any valid expression as long as they each resolve to an array. $setEquals
treats the arrays as sets.
In MongoDB, the $setDifference
aggregation pipeline operator accepts two sets and performs a relative complement of the second set relative to the first. It returns an array containing the elements that only exist in the first set.
$setDifference
accepts two arguments, both of which can be any valid expression as long as they each resolve to an array. $setDifference
treats the arrays as sets.