The official MongoDB Node.js driver
APACHE-2.0 License
Bot releases are hidden (Show)
Published by nbbeeken about 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.12 of the mongodb package!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Published by nbbeeken about 3 years ago
The MongoDB Node.js team is pleased to announce version 4.1.1 of the mongodb package!
We introduced better organization and consistency to our existing errors in an effort to provide more detailed error types that can help identify issues clearly and quickly. Our readme has a new section that describes how to handle errors thrown by the driver and defines our approach to semver in the context of errors. Notably, we recommend only using instanceof
checks to filter for a given error class as we do not guarantee error messages or names will be preserved between patch releases, only the subclass hierarchy.
Thanks so much to our summer interns @andymina and @W-A-James for undertaking this effort!
findOne()
once again correctly returns null
when no match is found instead of undefined
. This change was unintentional and not consistent with our other APIs. It slipped through testing due to the nature of undefined
and null
being nearly (==
) but not actually (===
) equal. We apologize if this results in the need for any code changes.This release also addresses some Typescript issues that require further explanation, let's dive in:
Starting in MongoDB 4.4 projections can accept aggregation expressions and aggregation syntax.
This empowers users to create some pretty amazing and complex data model transformations on the database side.
Unfortunately, our initial release of typescript typing for projections was too narrow to allow these use cases and still pass the compiler checks.
Now projections are generic objects and the result of a cursor with a projection is typed as a generic object by default.
The recommended usage for projections alongside typescript is as follows:
interface Pet {
name: string;
buddies: Pet[];
}
interface PetBuddyCount {
name: string;
buddyCount: number;
}
const pets = db.collection<Pet>('pets');
const petBuddyCounts = await pets.find().project<PetBuddyCount>({
name: 1,
buddyCount: { $size: '$buddies' },
}).toArray();
By using a parameterized .project
call you can now get the correct type information on the petBuddyCounts
array.
You will need to build the projection type yourself based on the projection you define for your query, but this has the benefit of constraining your results to precisely your type expectations.
In our initial typescript release the find
and findOne
methods accepted a generic parameter that was passed to the filter argument of the API.
find<T>(f: Filter<T>): FindCursor<T>
Due to how typescript automatically resolves the types of generics, one could run into an issue when specifying a filter that was incorrectly typed.
The code below should be a Typescript error, TS hints to us the name
is a string
so it should only allow an array of string
for $in
.
// (using the same pets collection from the last example)
pets.find({ name: { $in: [1, 2] } });
// instead of the expected FindCursor<Pet> type TS was resolving to:
const res: FindCursor<{name: {$in: number[]}}> = pets.find(/* same arg as above */);
It uses the incorrectly typed filter that does not match the schema of Filter<TSchema>
to automatically resolve a crazy return type.
The function definition has now been updated to be:
find<T>(f: Filter<TSchema>): FindCursor<T>
So the Filter argument will no longer be automatically resolved to the passed in type, giving us the typescript compiler errors we love so much!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Published by nbbeeken about 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.11 of the mongodb package!
This patch addresses a few bugs listed below.
Notably, we fixed an issue with the way we imported one of our optional dependencies that blocked webpack bundling.
If you are a webpack user you will still get warnings for our optional dependencies (if you don't use them).
You can hush the warnings by adding this option to your webpack config:
{
// ...
externals: [
'mongodb-client-encryption',
'aws4',
'saslprep',
'kerberos',
'snappy',
'bson-ext',
],
// ...
}
It is important to note that this will leave the imports in place and not pull in the code to your bundle. If you later do adopt using these dependencies you'll want to revert the relevant setting.
We invite you to try the mongodb package immediately, and report any issues to the NODE project.
Published by nbbeeken about 3 years ago
The MongoDB Node.js team is pleased to announce version 4.1.0 of the mongodb package!
This release includes load balancer support, intended for use with the beta Serverless platform. When using the driver with Serverless, the SRV URI will automatically put the driver into this mode. When wanting to use a non-SRV URI one must add the loadBalanced=true
option to the URI to put the driver into this mode. Being in this mode enables the driver to properly route transactions and cursors to the correct service behind the load balancer.
The release also fixes an important bug where the original release of the v4 driver enabled command monitoring by default, which caused many reported observations of performance degradation when upgrading from v3 of the driver. Command monitoring is now once again disabled by default and must be enabled by passing in { monitorCommands: true }
to the client if desired.
| void
in declaration of Promise overload of rename()
(#2922) (58c1e84)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Published by dariakp over 3 years ago
The MongoDB Node.js team is pleased to announce version 4.0.1 of the mongodb package!
This release fixes two small but important bugs from our 4.0.0 release:
We hope this improves your upgrade experience!
db()
before MongoClient is connected (#2889) (51ea86d)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is delighted to announce the major version release 4.0.0 of the MongoDB Node.js Driver!
We finally did it! The major version release of the MongoDB driver is now generally available! This release represents over a year's worth of effort that couldn't have been done without stellar contributions from the community and our Node.js DBX team. We hope you give it a try and are able to upgrade smoothly! 🎉
The biggest news is our migration to Typescript 🥳 offering first class support of type definitions in the driver itself.
Some cool new MongoDB 5.0 features now supported in the driver are:
Below are only the changes since our last beta release, for the full set of breaking changes look at the upgrade guide here and for the full set of new features, take a look here.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.10 of the mongodb package!
This patch addresses a few bugs listed below. Notably the bsonRegExp
option is now respected by the underlying BSON library, you can use this to decode regular expressions that contain syntax not permitted in native JS RegExp objects. Take a look at this example:
await collection.insertOne({ a: new BSONRegExp('(?-i)AA_') })
await collection.findOne({ a: new BSONRegExp('(?-i)AA_') }, { bsonRegExp: true })
// { _id: ObjectId, a: BSONRegExp { pattern: '(?-i)AA_', options: '' } }
Also there was an issue with Cursor.forEach
where user defined forEach callbacks that throw errors incorrectly handled catching errors. Take a look at the comments in this example:
collection.find({}).forEach(doc => {
if(doc.bad) throw new Error('bad document!');
}).catch(error => {
// now this is called! and error is `bad document!`
})
// before this fix the `bad document!` error would be thrown synchronously
// and have to be caught with try catch out here
We invite you to try the mongodb package immediately, and report any issues to the NODE project.
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.6 of the mongodb package!
This is on the larger side of the beta releases we've done so far we're getting closer to calling this version official.
As a breaking change in this release we now make use of the new MongoDriverError
and MongoServerError
to clarify where the issue arose from. All of the errors that our driver throws subclass from MongoError
so its possible to filter in catch blocks using instanceof
. Take a look at this example:
// without calling .connect()
await c.insertOne({ a: 1 })
// Uncaught MongoDriverError: MongoClient must be connected before calling MongoClient.prototype.db
// at MongoClient.db (lib/mongo_client.js)
await c.insertOne({ _id: /a/ })
// Uncaught MongoServerError: can't use a regex for _id
// at lib/operations/insert.js {
// index: 0,
// code: 2
// }
Here's the highlights:
.find()
and update specifiers in findOneAndUpdate()
await collection.insertOne({ a: new BSONRegExp('(?-i)AA_') })
await collection.findOne({ a: new BSONRegExp('(?-i)AA_') }, { bsonRegExp: true })
// { _id: ObjectId, a: BSONRegExp { pattern: '(?-i)AA_', options: '' } }
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Published by dariakp over 3 years ago
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.5 of the driver!
This release further improves our TypeScript support with consistent enum naming and a better list of exported types.
We invite you to try the mongodb package immediately, and report any issues to the NODE project.
Published by dariakp over 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.9 of the driver!
This release fixes a major performance bug in bulk write operations, which was inadvertently introduced by an incomplete code change in the previous release. The bug resulted in redundant array iterations and caused exponential increases in bulk operation completion times. Thank you Jan Schwalbe for bringing this to our attention!
We invite you to try the mongodb package immediately, and report any issues to the NODE project.
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.8 of the mongodb package!
Thanks to the quick adoption of the previous new patch by the mongoose package (https://github.com/Automattic/mongoose/pull/10265) a small bug was identified when connections to mongodb would timeout causing unnecessary clean up operations to run. Thank you @vkarpov15!
We invite you to try the mongodb package immediately, and report any issues to the NODE project.
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.7 of the driver
This patch addresses a number of bug fixes. Notably, there was an interesting javascript related issue with sorting documents. It only impacts users using numerical keys in their documents.
> { a: 'asc', [23]: 'asc' }
{ [23]: 'asc', a: 'asc' } // numbers come first
In javascript, numerical keys are always iterated first when looping over the keys of an object followed by the chronological specification of each string key. This effectively changes the ordering of a sort document sent to mongodb. However our driver does accept sort specification in a variety of ways and one way to avoid this problem is passing an array of tuples:
[['a', 'asc'], ['23', 'asc']]
This ensures that mongodb is sent the 'a'
key as the first sort key and '23'
as the second.
We invite you to try the driver immediately, and report any issues to the NODE project.
Thanks very much to all the community members who contributed to this release!
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 4.0.0.beta.4 of the driver.
This beta release brings optional support for Typescript generics when defining your collections
// Example:
interface Pet {
type: 'cat' | 'dog' | 'fish'
}
const collection = db.collection<Pet>()
await collection.findOne({}).toArray() // returns Pet[]
as well as strong typing for events emitted by the MongoClient
. For example, when listening to .on('commandStarted' event => ...)
, event
here will be a CommandStartedEvent
object.
We have a few breaking changes listed below, notably the node driver now aligns with other drivers by using the returnDocument
option when determining whether to return the document before
or after
the update in findOneAndUpdate
and findOneAndReplace
.
NODE-2995: Add shared metadata MongoClient (#2772) (9073d54)
NODE-3074: update estimated document count for v1 api (#2764) (146791c)
NODE-3109: prevent servername from being an IP (#2771) (27089be)
NODE-3166: allowInvalidHostnames and allowInvalidCertificates flags are ignored (#2784) (a769cf8)
NODE-3174: Preserve sort key order for numeric string keys (#2788) (440de41)
NODE-3176: handle errors from MessageStream (#2780) (76b110e)
NODE-3194: Ignore undefined and null options in MongoClient constructor (#2800) (8bb92f9)
NODE-3197: revert setImmediate in waitQueue (#2802) (6c0dfef)
NODE-3206: Make distinct use any[] type instead of Document[] (#2795) (b45e3b3)
NODE-3219: topology no longer causes close event (#2792) (6cd982f)
NODE-1812: replace returnOriginal with returnDocument option (#2803) (1cdc8a8)
NODE-3157: update find and modify interfaces for 4.0 (#2799) (29512da)
We invite you to try the driver immediately, and report any issues to the NODE project.
To try the beta use the following command:
npm install [email protected]
Thanks very much to all the community members who contributed to this release!
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.6 of the driver
This patch addresses a number of bugs listed below.
Most notably, for client side encryption users upgrading to this version of the driver along with the new version of [email protected] will alleviate the potential deadlock case if your connection pool was fully utilized. There will now be an internal MongoClient that will be used for metadata look ups (e.g, listCollections
) when the pool size is under certain constraints. The events generated from this client are forwarded to the client instance you initialize so it is possible to monitor all events.
We invite you to try the driver immediately, and report any issues to the NODE project.
Thanks very much to all the community members who contributed to this release!
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.3 of the driver
This release brings us closer to the RC release for the fully typescript enabled version 4.0.0 of the driver.
You can expect a full migration and detailed list of changes with the upcoming RC.
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.5 of the driver!
In this patch there is a fix surrounding an issue some users were encountering in serverless environments when using the Unified Topology. If the nodejs process went unused for a great amount of time there was an intermittent issue that would cause startSession
to fail, however, issuing a dummy read request would resolve the problem. The session support check is now done after server selection meaning the driver has the most up to date information about the MongoDB deployment before utilizing sessions. We encourage any user's that implemented workarounds to updated their driver and make use of this fix.
In addition, the previous release of our driver added a warning about an upcoming change in the v4 version of the driver about how users can specify their write concern options. We've updated the driver to use nodejs's process.emitWarning
API in nearly all cases where the driver prints something out, as well as limit most warning messages to only be printed once.
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.2 of the driver
This release brings us closer to the RC release for the fully typescript enabled version 4.0.0 of the driver.
You can expect a full migration and detailed list of changes with the upcoming RC.
Reference: https://docs.mongodb.com/drivers/node
API: https://mongodb.github.io/node-mongodb-native/4.0
Changelog: https://github.com/mongodb/node-mongodb-native/blob/4.0/HISTORY.md
Published by nbbeeken over 3 years ago
This beta release addresses a few bugs relating to using CSFLE with the beta version of the driver. As well as a fix for BulkWriteResult and BulkWriteError to correctly reflect the operation's result information.
You can take a look at the raw updates list in our HISTORY.md file, we are intending to do a complete rundown of features and fixes with the v4.0.0 release.
You can give it a try with:
npm install mongodb@beta
If you have any suggestions about clarifying documentation or if you run into any issues or have any feature ideas please let us know! You can make an account and submit tickets to our JIRA project here.
Reference: https://docs.mongodb.com/drivers/node
API: https://mongodb.github.io/node-mongodb-native/4.0
Changelog: https://github.com/mongodb/node-mongodb-native/blob/4.0/HISTORY.md
Published by nbbeeken over 3 years ago
The MongoDB Node.js team is pleased to announce version 3.6.4 of the driver
The full set of $explain verbosity settings are now supported:
queryPlanner
queryPlannerExtended
executionStats
allPlansExecution
In the following commands:
aggregate()
(MDB 3.0+)find()
(MDB 3.0+)remove()
(MDB 3.0+)update()
(MDB 3.0+)distinct()
(MDB 3.2+)findAndModify()
(MDB 3.2+)mapReduce()
(MDB 4.4+)You can get a lot of insight into the performance of a query or optimization using these fine grained reports.
To learn more about how to use explain read here.
We removed automatic direct connection for the unified topology in the 3.6.3 release of the driver. This change was preparatory for the 4.0 version of the driver, where we'll always perform automatic discovery. To avoid making this kind of change in a patch release, this version restores automatic direct connection when connecting to a single host using the unified topology without a specified replicaSet and without directConnection: false, in line with previous 3.6 releases.
NOTE: In the next major version the
unifiedTopology
is the only Topology and it is required to either specify areplicaSet
name or enabledirectConnection
in order to connect to single nodes in a replica set.
There are no functional changes to the driver to support using Azure and GCP keystores but a new mongodb-client-encryption release (v1.2.0) can be found here which prominently features support for these key stores.
We invite you to try the driver immediately, and report any issues to the NODE project.
Thanks very much to all the community members who contributed to this release!
Db
Published by nbbeeken almost 4 years ago
The MongoDB Node.js team is pleased to announce a beta version v4.0.0-beta.0 of the driver.
A major motivation for releasing this beta was the migration of the entire code base to TypeScript. While we took special care to ensure a smooth transition, we imagine such a dramatic change might reveal unexpected issues. This beta release makes it easy to easily check compatibility with your application and make use of the included type definitions.
Additionally, we are publishing an early version of the new API documentation https://mongodb.github.io/node-mongodb-native/4.0.
You can take a look at the raw updates list in our HISTORY.md file, we are intending to do a complete rundown of features and fixes with the v4.0.0 release.
You can give it a try with:
npm install mongodb@beta
If you have any suggestions about clarifying documentation or if you run into any issues or have any feature ideas please let us know! You can make an account and submit tickets to our JIRA project here.
Reference: https://docs.mongodb.com/drivers/node
API: https://mongodb.github.io/node-mongodb-native/4.0
Changelog: https://github.com/mongodb/node-mongodb-native/blob/4.0/HISTORY.md