What's New新增功能
On this page本页内容
What's New in 5.75.7中的新增功能What's New in 5.65.6中的新增功能What's New in 5.55.5中的新增功能What's New in 5.45.4中的新增功能What's New in 5.35.3中的新增功能What's New in 5.25.2中的新增功能What's New in 5.15.1中的新增功能What's New in 5.05.0中的新增功能What's New in 4.154.15中的新增功能What's New in 4.144.14中的新增功能What's New in 4.134.13中的新增功能What's New in 4.124.12中的新增功能What's New in 4.114.11中的新增功能What's New in 4.104.10中的新增功能What's New in 4.94.9中的新增功能What's New in 4.84.8中的新增功能What's New in 4.74.7中的新增功能What's New in 4.64.6中的新增功能What's New in 4.54.5中的新增功能What's New in 4.44.4中的新增功能What's New in 4.34.3中的新增功能What's New in 4.24.2中的新增功能What's New in 4.14.1中的新增功能What's New in 4.04.0中的新增功能What's New in 3.73.7中的新增功能What's New in 3.63.6中的新增功能
Learn what's new in:了解中的新增内容:
- Version 5.7
- Version 5.6
- Version 5.5
- Version 5.4
- Version 5.3
- Version 5.2
- Version 5.1
- Version 5.0
- Version 4.15
- Version 4.14
- Version 4.13
- Version 4.12
- Version 4.11
- Version 4.10
- Version 4.9
- Version 4.8
- Version 4.7
- Version 4.6
- Version 4.5
- Version 4.4
- Version 4.3
- Version 4.2
- Version 4.1
- Version 4.0
- Version 3.7
- Version 3.6
What's New in 5.75.7中的新增功能
The Node.js driver v5.7 release includes the following features:Node.js驱动程序v5.7版本包括以下功能:
Deprecation Notice弃用通知
The following Write Concern options are deprecated:不赞成使用以下“写入关注”选项:wtimeout
j
fsync
To specify the write concern behavior, use the要指定写关注行为,请改用wtimeoutMS
andjournal
options instead.wtimeoutMS
和journal
选项。To learn more about these options, see the Connection Options page.要了解有关这些选项的详细信息,请参阅连接选项页面。SSL options and other transport encryption options are deprecated.SSL选项和其他传输加密选项已弃用。To learn more about the deprecated options and which options to use instead, see the Legacy SSL options deprecated section in the v5.7.0 Release Highlights linked at the end of this section.要了解有关不推荐使用的选项以及要使用哪些选项的更多信息,请参阅本节末尾链接的v.7.0版本亮点中的“旧版SSL选项不推荐使用”部分。
A new option forfindOneAnd...
compound methods.findOneAnd...
的一个新选项复合方法。TheincludeResultMetaData
option allows you to specify whether to include information about the operation result.includeResultMetaData
选项允许您指定是否包含有关操作结果的信息。See the Compound Operations Built-in Methods section for more information.有关详细信息,请参阅复合操作内置方法部分。Support for change stream split events which enables processing change stream documents that exceed the 16MB maximum BSON size limit.支持变更流拆分事件,允许处理超过16MB最大BSON大小限制的变更流文档。An API to manage Search indexes from within your application.API,用于从应用程序中管理搜索索引。To learn more, see Search Indexes.要了解更多信息,请参阅搜索索引。
To learn more about this release, see the v5.7.0 Release Highlights.要了解有关此版本的更多信息,请参阅v.7.0版本亮点。
What's New in 5.65.6中的新增功能
The Node.js driver v5.6 release includes the following features:Node.js驱动程序v5.6版本包括以下功能:
The driver now supports Node.js v20.该驱动程序现在支持Node.js v20。The driver can return a cursor as the response to a server command when you call the当您调用runCursorCommand()
method.runCursorCommand()
方法时,驱动程序可以返回一个游标作为对服务器命令的响应。To learn more about this feature, see the runCursorCommand API documentation.要了解有关此功能的更多信息,请参阅runCursorCommand
API文档。
Support for specifying time series collection creation options bucketMaxSpanSeconds支持指定时间序列集合创建选项and bucketRoundingSeconds
.
bucketMaxSpanSeconds
和
bucketRoundingSeconds
。
To learn more about these time series collection options, see Set Granularity for Time Series Data in the Server manual.要了解有关这些时间序列集合选项的更多信息,请参阅服务器手册中的设置时间序列数据的粒度。
To learn more about this release, see the v5.6.0 Release Highlights.要了解有关此版本的更多信息,请参阅v5.6.0版本亮点。
What's New in 5.55.5中的新增功能
New features of the 5.5 Node.js driver release include:5.5 Node.js驱动程序版本的新功能包括:
The driver now accurately detects Function-as-a-Service (FaaS) environments in AWS by considering AWS environment variables only if they begin with驱动程序现在通过只考虑以AWS_Lambda_
.AWS_Lambda_
开头的AWS环境变量来准确检测AWS中的功能即服务(FaaS)环境。You must upgrade如果要使用Queryable encryption功能创建加密集合,则必须将mongodb-client-encryption
to version 2.8.0 or later if you want to create an encrypted collection by using the Queryable Encryption feature.mongodb-client-encryption
升级到2.8.0或更高版本。
What's New in 5.45.4中的新增功能
New features of the 5.4 Node.js driver release include:5.4 Node.js驱动程序版本的新功能包括:
Deprecation Notice弃用通知
ThecollStats
operation is deprecated. Use the $collStats aggregation operator instead.collStats
操作已弃用。请改用$collStats
聚合运算符。The TypeScript interface passed to the传递给db.command()
method incorrectly includes certain options.db.command()
方法的TypeScript接口错误地包含了某些选项。These options have been deprecated.这些选项已被弃用。
TheChangeStream.tryNext
method now uses the schema-specificTChange
generic type instead of theDocument
interface.ChangeStream.tryNext
方法现在使用特定于模式的TChange
泛型类型,而不是Document
接口。
To learn more, see the v5.4.0 Release Highlights.要了解更多信息,请参阅v.4.0版本亮点。
What's New in 5.35.3中的新增功能
New features of the 5.3 Node.js driver release include:5.3 Node.js驱动程序版本的新功能包括:
Deprecation Notice弃用通知
The不赞成使用forEach()
cursor method, which allows you to iteratively access results from queries and aggregations, is deprecated.forEach()
游标方法,该方法允许您迭代访问查询和聚合的结果。Use the请改用for await...of
syntax instead, as shown here.for await...of
语法,如这里所示。TheaddUser()
method is deprecated. UsecreateUser()
instead.addUser()
方法已弃用。请改用createUser()
。ThekeepAlive
andkeepAliveInitialDelay
connection options are deprecated.keepAlive
和keepAliveInitialDelay
连接选项已弃用。Methods that contain duplicated functionality in the不赞成使用BulkWriteResult
class are deprecated.BulkWriteResult
类中包含重复功能的方法。See the API documentation有关不推荐使用的方法和首选替代方法的完整列表,请参阅API文档for a full list of deprecated methods and the preferred alternatives.
。
Client metadata now includes function as a service (FaaS) environment information and alternative runtime detection.客户端元数据现在包括功能即服务(FaaS)环境信息和替代运行时检测。The driver now allows SRV record addresses that contain a trailing dot.驱动程序现在允许包含尾随点的SRV记录地址。UpdateResult.upsertedId
now returns null when no documents are updated.现在,当没有文档更新时,返回null
。
To learn more, see the v5.3.0 Release Highlights.要了解更多信息,请参阅v.3.0版本亮点。
What's New in 5.25.2中的新增功能
New features of the 5.2 Node.js driver release include:5.2 Node.js驱动程序版本的新功能包括:
The driver now supports automatically obtaining Azure credentials when using automatic Queryable Encryption.该驱动程序现在支持在使用自动可查询加密时自动获取Azure凭据。
To learn more, see the v5.2.0 Release Highlights.要了解更多信息,请参阅v.2.0版本亮点。
What's New in 5.15.1中的新增功能
New features of the 5.1 Node.js driver release include:5.1 Node.js驱动程序版本的新功能包括:
The driver now supports automatic serialization of JavaScript该驱动程序现在支持JavaScriptbigint
toBSON.Long
.bigint
到BSON.Long
的自动序列化。It also supports the deserialization of当BSON.Long
values returned from the server tobigint
values when theuseBigInt64
flag is passed as true.useBigInt64
标志传递为true
时,它还支持将服务器返回的BSON.Long
值反序列化为bigint
值。
To learn more, see the v5.1.0 Release Highlights.要了解更多信息,请参阅v5.1.0版本亮点。
What's New in 5.05.0中的新增功能
Breaking Changes in v5.0v5.0中的突破性更改
Version 5.0 of the Node.js driver is not compatible with Node.js v12 or earlier.Node.js驱动程序的5.0版本与Node.js v12或更早版本不兼容。If you want to use this version of the driver, You must use Node.js v14.20.1 or greater.如果你想使用这个版本的驱动程序,你必须使用Node.js v14.20.1或更高版本。This release removes support for callbacks in favor of a promise-based API.此版本取消了对回调的支持,转而支持基于promise-based的API。The following list provides some strategies for callback users to adopt this version:以下列表为回调用户提供了一些采用此版本的策略:Migrate to the promise-based API (recommended)迁移到基于承诺的API(推荐)Use the promise-based API and使用基于承诺的APIutil.callbackify
Add添加mongodb-legacy
to continue using callbacksmongodb-legacy
以继续使用回调
For more information about these strategies, see Changes in the MongoDB Node.js Driver v5.有关这些策略的更多信息,请参阅MongoDB Node.js Driver v5中的更改。
This release removes support for the此版本删除了对Collection.insert()
,Collection.update()
, andCollection.remove()
helper methods.Collection.insert()
、Collection.update()
和Collection.remove()
辅助方法的支持。The following list provides instructions on how to replace the functionality of the removed methods:以下列表提供了有关如何替换已删除方法的功能的说明:Migrate from从Collection.insert()
toinsertOne()
orinsertMany()
Collection.insert()
迁移到insertOne()
或insertMany()
Migrate from从Collection.update()
toupdateOne()
orupdateMany()
Collection.update()
迁移到updateOne()
或updateMany()
Migrate from从Collection.remove()
todeleteOne()
ordeleteMany()
Collection.remove()
迁移到deleteOne()
或deleteMany()
To view a full list of breaking changes introduced in this version, see the Breaking Changes section in the Upgrade guide.要查看此版本中引入的中断更改的完整列表,请参阅升级指南中的中断更改部分。
New features of the 5.0 Node.js driver release include:5.0 Node.js驱动程序版本的新功能包括:
By default, the driver no longer checks types referenced in dot notation unless the默认情况下,除非显式使用StrictFilter
type annotation is explicitly used.StrictFilter
类型注释,否则驱动程序不再检查点表示法中引用的类型。To learn more about this change, see the Typescript fundamentals page.要了解有关此更改的更多信息,请参阅Typescript基础知识页面。NoteThis change is for Typescript only, and does not affect queries or operations at runtime.此更改仅适用于Typescript,不会影响运行时的查询或操作。Optional installation of可选安装@aws-sdk/credential-providers
as a peer dependency.@aws-sdk/credential-providers
作为对等依赖项。The driver no longer includes AWS SDK modules by default.默认情况下,驱动程序不再包含AWS SDK模块。Use the following使用以下npm
command to install the SDK:npm
命令安装SDK:npm install --save "@aws-sdk/credential-providers@^3.201.0"
If you install the SDK,如果您安装了SDK,npm
notifies you if the version of the SDK you installed is incompatible with the driver.npm
会通知您安装的SDK版本是否与驱动程序不兼容。Once you install the dependency successfully, the driver uses the AWS SDK itself to manage credentials from the environment.一旦成功安装了依赖项,驱动程序就会使用AWS SDK本身来管理环境中的凭据。
What's New in 4.154.15中的新增功能
New features of the 4.15 Node.js driver release include:4.15 Node.js驱动程序版本的新功能包括:
Support for AWS IAM roles for service accounts.支持服务帐户的AWS IAM角色。
To learn more, see the v4.15.0 Release Highlights.要了解更多信息,请参阅v4.15.0版本亮点。
What's New in 4.144.14中的新增功能
Upgrade from v4.13 to v4.14从v4.13升级至v4.14
This version includes a fix to a memory leak introduced in v4.13. We recommend upgrading to v4.14.此版本包含对v4.13中引入的内存泄漏的修复。我们建议升级到v4.14。
New features of the 4.14 Node.js driver release include:4.14Node.js驱动程序版本的新功能包括:
Fixed a memory leak introduced in v4.13.修复了v4.13中引入的内存泄漏。Deprecated methods and options that reference the legacy Logger.不推荐使用引用传统Logger的方法和选项。
What's New in 4.134.13中的新增功能
New features of the 4.13 Node.js driver release include:4.13 Node.js驱动程序版本的新功能包括:
Automatic cancellation of in-flight operations in the connection pool when the driver encounters network timeout errors.当驱动程序遇到网络超时错误时,自动取消连接池中的运行中操作。Disabled causal consistency in implicit sessions to prevent conflicting with the禁用隐式会话中的因果一致性,以防止与linearizable
andavailable
read concern settings.linearizable
和available
读取关注设置发生冲突。Fixed a potential memory leak by ensuring that the driver destroys通过确保驱动程序在MessageStream
instances whenever their connections are destroyed.MessageStream
实例的连接被破坏时破坏MessageStream
实例,修复了潜在的内存泄漏问题。
What's New in 4.124.12中的新增功能
Upgrade Driver to Version 4.12.1将驱动程序升级至4.12.1版本
The 4.12.1 Node.js driver includes a fix to a regression in monitoring logic that could cause processes to crash.4.12.1 Node.js驱动程序修复了监控逻辑中可能导致进程崩溃的回归。
New features of the 4.12 Node.js driver release include:4.12 Node.js驱动程序版本的新功能包括:
Redefinition of the将ChangeStream
class as an async iterable.ChangeStream
类重新定义为异步可迭代类。You can use您可以在任何需要ChangeStream
instances in any context that expects anAsyncIterator
.AsyncIterator
的上下文中使用ChangeStream
实例。Notably, change streams can now be used in Javascript值得注意的是,变更流现在可以在Javascript中用于for-await
loops:for-await
循环:const changeStream = myColl.watch();
for await (const change of changeStream) {
console.log("Received change: ", change);
}
Fix to server monitoring when the driver skips monitoring events.修复驱动程序跳过监视事件时服务器监视的问题。In this release, the driver always updates its view of the topology when processing monitoring events.在这个版本中,驱动程序在处理监视事件时总是更新其拓扑视图。Performance improvements with buffering as a result of modification to data structures used internally in the driver.由于对驱动程序内部使用的数据结构进行了修改,缓冲区的性能得到了改善。
To learn more, see the v4.12.0 Release Highlights.要了解更多信息,请参阅v4.12.0版本亮点。
What's New in 4.114.11中的新增功能
Prioritization Order in Monitoring监控中的优先级排序
When connecting to MongoDB Server version 6.0 or later, the driver prioritizes electionId
settings before setVersion
settings during Server Discovery and Monitoring events. In previous versions, the prioritization order was reversed.
Changes to AWS Authentication
When you install the optional aws-sdk/credential-providers
dependency, the driver uses the AWS SDK to retrieve AWS credentials from the environment.
To learn more about this behavior, see the MONGODB-AWS section of the Authentication Mechanisms guide.
Mutually Recursive Schema Type Checking
This release includes added support for mutually recursive collection schema types. The driver also provides type safety for dot-notation queries up to a depth of eight in this release. At a depth greater than or equal to eight, Typescript successfully compiles your code but does not provide type safety. This depth limit on recursive types is a current limitation of TypeScript.
Example实例
Suppose we have a collection of type Collection<Author>
that contains the following mutually recursive types:
interface Author {
name: string;
bestBook: Book;
}
interface Book {
title: string;
author: Author;
}
TypeScript enforces type checking up to a depth of eight. The following code causes a TypeScript compilation error because the name
property value must be a string
type:
myColl.findOne({ 'bestBook.author.bestBook.title': 25 });
At a depth greater than or equal to eight, TypeScript compiles your code but no longer type checks it. For example, the following code assigns a number
to a string
property but does not cause a compilation error because the referenced property is at a depth of 10:
myColl.findOne({
'bestBook.author.bestBook.author.bestBook.author.bestBook.author.bestBook.author.name': 25
});
To learn more, see the v4.11.0 Release Highlights.要了解更多信息,请参阅v4.11.0版本亮点。
What's New in 4.104.10中的新增功能
New features of the 4.10 Node.js driver release include:
- Callback Deprecation
- Callbacks are now deprecated in favor of Promises. Callbacks will be removed in the next major release. The Node driver team recommends migrating to promises where possible:
- Use
async/await
syntax. - Use the Node.js callbackify utility:
require('util').callbackify(() => myColl.findOne())(callback)
- Use then
syntax:
myColl.findOne().then(res => callback(null, res), err => callback(err))
- Use
- If you are unable to migrate to Promises in a large codebase, you can use the legacy Node.js driver with optional callback support.
- Callbacks are now deprecated in favor of Promises. Callbacks will be removed in the next major release. The Node driver team recommends migrating to promises where possible:
To learn more, see v4.10.0 Release Highlights.
What's New in 4.94.9中的新增功能
New features of the 4.9 Node.js driver release include:
- Fixed an inconsistency with
writeConcern
options in the type definitions. - Included the latest BSON release, which adds automatic UUID support. See the BSON release notes here.
To learn more, see v4.9.0 Release Highlights.
What's New in 4.84.8中的新增功能
Upgrade from v4.8.0 to v4.8.1
Version 4.8.1 fixes a type regression issue introduced in v4.8.0. By upgrading to v4.8.1, you can specify _id
values and sub-documents when performing updates with the $set
or $setOnInsert
operators.
New features of the 4.8 Node.js driver release include:
- Added auto-completion and type safety for nested keys in an update filter
client.startSession()
can now be called before connecting to MongoDBestimatedDocumentCount()
method can now accept a comment
To learn more, see v4.8.0 Release Highlights.
What's New in 4.74.7中的新增功能
New features of the 4.7 Node.js driver release include:
- The
MongoClient.connect()
method is now optional when connecting to your MongoDB instance - Ability to compress messages with the
Zstandard
compression algorithm - Added support for the
maxConnecting
connection option - Ability for change stream documents to show your documents before and after an update
- Added support for new change stream fields related to Cluster to Cluster Replication
- The
estimatedDocumentCount()
method now uses the$count
database command - Improved connecting to MongoDB in the AWS Lambda Init phase
Deprecation Notice弃用通知
The ResumeOptions
interface is deprecated. Use the ChangeStreamCursorOptions
interface instead.
What's New in 4.64.6中的新增功能
New features of the 4.6 Node.js driver release include:
- Improved the
ChangeStreamDocument
in TypeScript. - Even distribution of server selection based on load across servers.
To learn more, see v4.6.0 Release Highlights.
What's New in 4.54.5中的新增功能
See v4.5.0 Release Highlights on GitHub.
What's New in 4.44.4中的新增功能
New features of the 4.4 Node.js driver release include:
- KMIP provider support when using CSFLE.
- TLS support when using CSFLE.
- Hostname canonicalization now accepts "none", "forward", and "forwardAndReverse" as
authMechanismProperties
when using GSSAPI. - In the 4.0.0 release of the driver, the deprecated
collection.count()
method was inadvertently changed to behave likecollection.countDocuments()
. In this release, thecollection.count()
method is updated to match legacy behavior:- If a query is provided,
collection.count()
behaves the same ascollection.countDocuments()
and performs a collection scan. - If no query is provided,
collection.count()
behaves the same ascollection.estimatedDocumentCount()
and relies on collection metadata.
ImportantDeprecation Notice弃用通知The
cursor.count()
method is deprecated and will be removed in the next major version, along withcollection.count()
. Use thecollection.estimatedDocumentCount()
orcollection.countDocuments()
methods instead. - If a query is provided,
What's New in 4.34.3中的新增功能
New features of the 4.3 Node.js driver release include:
- SOCKS5 support
- Option to disable UTF-8 validation
- Type inference for nested documents
What's New in 4.24.2中的新增功能
New features of the 4.2 Node.js driver release include:
srvMaxHosts
andsrvServiceName
DNS seedlist connection options
What's New in 4.14.1中的新增功能
New features of the 4.1 Node.js driver release include:
- Added load balanced connection support for all cluster types including the beta Serverless platform.
- Added support for the
advanceClusterTime()
method to determine if theClientSession
should update its cluster time.
What's New in 4.04.0中的新增功能
In this release of the driver, the deprecated collection.count()
method was inadvertently changed to behave like collection.countDocuments()
. This behavior is corrected in version 4.4.
New features of the 4.0 Node.js driver release include:
TypeScript
- We've migrated the driver to TypeScript. You can now harness the type hinting and intellisense features in editors that support it to develop your MongoDB applications. Enjoy the benefits of this work in pure JavaScript projects as well.
- The underlying BSON library used by this version is now migrated to TypeScript.
- Inline documentation is now consistently formatted to improve display in editors.
- If you are a user of the community types
@types/mongodb
, there will likely be issues adopting the types from our codebase. We could not achieve a one to one match in types due to the details of writing the codebase in TypeScript.
We'd love to hear your TypeScript related feature requests. Please submit ideas on our JIRA project here.
Key Changes
Node.js Version
The minimum supported version of Node.js is now v12.9 or greater for version 4 of the driver. Support for our 3.x branches will continue until midyear 2022 to allow time for users to upgrade.
3.x supports back to Node.js v4.
Cursor Improvements
Our Cursor implementation is now updated to make it clear what is possible before and after execution of an operation.
const fc = myColl.find({a: 2.3}).skip(1)
for await (const doc of fc) {
console.log(doc)
fc.limit(1) // incorrect usage, cursor already executing
}
There was inconsistency surrounding how the cursor would error if a setting was applied after cursor execution began. Now, the cursor will throw an error when attempting to apply operations in an invalid state, similar to the following:
MongoError: Cursor is already initialized
- Affected classes:
AbstractCursor
FindCursor
AggregationCursor
ChangeStreamCursor
(This is the underlying cursor forChangeStream
)ListCollectionsCursor
Cursor Stream API
Our Cursor types no longer extend Readable
directly. They must be transformed into a stream by calling cursor.stream()
.
const cursor = myColl.find({});
const stream = cursor.stream();
stream.on("data", data => console.log);
stream.on("error", () => client.close());
Use hasNext()
and next()
for manual iteration. Use for await of
syntax or any Promise
helpers for asynchronous iteration.
MongoClientOptions
Interface
With type hinting, you should find that options passed to a MongoClient
are enumerated and discoverable. We've made a large effort to process all options in the driver to give early warnings about incompatible settings to get your app up and running in a correct state quickly.
checkServerIdentity
is no longer checked before being passed to the underlying Node API. Previously, accepted values werefalse
, or a function. Now, the argument must be a function. Specifying a boolean will result in an error being thrown.- It is no longer required to specify
useUnifiedTopology
oruseNewUrlParser
.
createCollection()
This method no longer supports a strict
option, which returned an error if the collection did not exist. To assert the existence of a collection, use the listCollections()
method instead.
const collections = (await db.listCollections({}, { nameOnly: true })
.toArray()).map(
({name}) => name
);
if (!collections.includes(myNewCollectionName)) {
throw new Error(`${myNewCollectionName} doesn't exist`);
}
BulkWriteError
→ MongoBulkWriteError
BulkWriteError
is now renamed to MongoBulkWriteError
.
When running bulk operations that make writes you can encounter errors depending on your settings. Import the new class name MongoBulkWriteError
when testing for errors in bulk operations.
DB
DB
is no longer an EventEmitter
. Listen for events directly from your MongoClient
instance.
Collection.group()
The Collection.group()
helper, deprecated since MongoDB 3.4, is now removed. Use the aggregation pipeline $group operator instead.
Authentication
gssapiServiceName
is now removed. Use authMechanismProperties.SERVICE_NAMEin the URI or as an option on
MongoClientOptions
.Example?authMechanismProperties.SERVICE_NAME
// or
new MongoClient(url, { SERVICE_NAME: "alternateServiceName" })- Specifying username and password as options is only supported in the URI or as an option on
MongoClientOptions
.Examplenew MongoClient("mongodb://username:password@<host><port>")
// or
new MongoClient(url, { auth: { username: "<>", password: "<>" } })
GridStore
Removal
The GridStore API (already deprecated in 3.x) is now replaced with GridFSBucket
. For more information on GridFS
, see the mongodb manual.
Below are some snippets that represent equivalent operations.
Construction
// old way
const gs = new GridStore(db, filename, mode[, options])
// new way
const bucket = new GridFSBucket(client.db('test')[,options])
File Seeking
GridFSBucket uses the Node.js Stream API. You can replicate file seeking by using the start
and end
options, creating a download stream from your GridFSBucket
.
bucket.openDownloadStreamByName(filename, { start: 0, end: 100 })
File Upload & Download
await client.connect();
const filename = 'test.txt'; // whatever local file name you want
const db = client.db();
const bucket = new GridFSBucket(db);
fs.createReadStream(filename)
.pipe(bucket.openUploadStream(filename))
.on('error', console.error)
.on('finish', () => {
console.log('done writing to db!');
bucket
.find()
.toArray()
.then(files => {
console.log(files);
bucket
.openDownloadStreamByName(filename)
.pipe(fs.createWriteStream('downloaded_' + filename))
.on('error', console.error)
.on('finish', () => {
console.log('done downloading!');
client.close();
});
});
});
GridFSBucket
does not need to be closed like GridStore
.
File Deletion
// old way
GridStore.unlink(db, name, callback);
// new way
bucket.delete(file_id);
Finding File Metadata
File metadata that used to be accessible on the GridStore
instance can be found by querying the bucket.
const fileMetaDataList: GridFSFile[] = bucket.find({}).toArray();
Unified Topology
- We internally now only manage a
unifiedTopology
when you connect to amongod
. The differences between this and previous versions is detailed here. - It is no longer required to specify
useUnifiedTopology
oruseNewUrlParser
. - You must use the new
directConnection
optionto connect to uninitialized replica set members.
Explain
Support is now added for fine-grained verbosity modes. 现在增加了对细粒度冗长模式的支持。You can learn more about each mode here.
Command Monitoring
The instrument()
method is now removed. Use command monitoring instead. See our guide on command monitoring for more information.
Detailed List
To view a full list of breaking changes introduced in this version, see the Breaking Changes section in the Upgrade guide.
What's New in 3.73.7中的新增功能
New features of the 3.7 Node.js driver release include:
- Added support for load balancer mode while enabling the
useUnifiedTopology
option - Added support for Stable API while enabling the
useUnifiedTopology
option
What's New in 3.63.6中的新增功能
New features of the 3.6 Node.js driver release include:
- Added support for the MONGODB-AWS authentication mechanism using Amazon Web Services (AWS) Identity and Access Management (IAM) credentials
- The find()
method supports
allowDiskUse()
for sorts that require too much memory to execute in RAM - The update() and replaceOne() methods support index hints
A reduction in recovery time for topology changes and failover events减少拓扑更改和故障切换事件的恢复时间- Improvements in validation testing for the default writeConcern
Authentication requires fewer round trips to the server, resulting in faster connection setup身份验证需要更少的往返服务器的次数,从而加快连接设置- Shorter Salted Challenge Response Authentication Mechanism (SCRAM) conversations
Ability to create collections and indexes for multiple document transactions能够为多个文档事务创建集合和索引Running validation for a collection in the background在后台运行集合验证