Creates a new Db instance创建新的Db
实例
The MongoClient for the database.数据库的MongoClient
。
The name of the database this instance represents.此实例所代表的数据库的名称。
Optional
options: DbOptionsOptional settings for Db constructionDb
构造的可选设置
Static
SYSTEM_Static
SYSTEM_Static
SYSTEM_Static
SYSTEM_Static
SYSTEM_Static
SYSTEM_The current readPreference of the Db. If not explicitly defined for this Db, will be inherited from the parent MongoClientDb
的当前readPreference
。如果没有为此Db明确定义,则将从父MongoClient
继承
Check if a secondary can be used (because the read preference is not set to primary)检查是否可以使用辅助(因为读取首选项未设置为primary)
Execute an aggregation framework pipeline against the database, needs MongoDB >= 3.6针对数据库执行聚合框架管道,需要MongoDB>=3.6
An array of aggregation stages to be executed要执行的聚合阶段数组
Optional
options: AggregateOptionsOptional settings for the command命令的可选设置
Returns a reference to a MongoDB Collection. If it does not exist it will be created implicitly.返回对MongoDB集合的引用。如果它不存在,它将被隐式创建。
the collection name we wish to access.我们希望访问的集合名称。
return the new Collection instance返回新的Collection
实例
Fetch all collections for the current db.获取当前数据库的所有集合。
Optional
options: ListCollectionsOptionsOptional settings for the command命令的可选设置
Execute a command执行命令
The command to run要运行的命令
Optional
options: RunCommandOptionsOptional settings for the command命令的可选设置
This command does not inherit options from the MongoClient.此命令不会从MongoClient继承选项。
The driver will ensure the following fields are attached to the command sent to the server:驱动程序将确保以下字段附加到发送到服务器的命令中:
lsid
- options.session
$readPreference
- options.readPreference
进行配置$db
- If the client has a serverApi setting:如果客户端具有serverApi设置:
apiVersion
apiStrict
apiDeprecationErrors
When in a transaction:在事务中:
readConcern
- TransactionOptions
上设置的readConcernwriteConcern
- TransactionOptions
上设置的writeConcernAttaching any of the above fields to the command will have no effect as the driver will overwrite the value.将上述任何字段附加到命令将不会产生任何效果,因为驱动程序将覆盖该值。
Create a new collection on a server with the specified options. 使用指定的选项在服务器上创建新集合。Use this to create capped collections.使用此选项可以创建封顶集合。
More information about command options available at /v7.0/reference/command/create/有关命令选项的详细信息,请访问/v7.0/reference/command/create/
The name of the collection to create要创建的集合的名称
Optional
options: CreateCollectionOptionsOptional settings for the command命令的可选设置
Creates an index on the db and collection.在数据库和集合上创建索引。
Name of the collection to create the index on.要在其上创建索引的集合的名称。
Specify the field to index, or an index specification指定要索引的字段或索引规范
Optional
options: CreateIndexesOptionsOptional settings for the command命令的可选设置
Drop a collection from the database, removing it permanently. New accesses will create a new collection.从数据库中删除集合,并将其永久删除。新的访问将创建一个新的集合。
Name of collection to drop要删除的集合的名称
Optional
options: DropCollectionOptionsOptional settings for the command命令的可选设置
Drop a database, removing it permanently from the server.删除数据库,将其从服务器中永久删除。
Optional
options: CommandOperationOptionsOptional settings for the command命令的可选设置
Retrieves this collections index info.检索此集合的索引信息。
The name of the collection.集合的名称。
Optional
options: IndexInformationOptionsOptional settings for the command命令的可选设置
List all collections of this database with optional filter使用可选筛选器列出此数据库的所有集合
Query to filter collections by查询以筛选集合
Optional settings for the command命令的可选设置
Optional
filter: DocumentOptional
options: ListCollectionsOptionsRetrieve the current profiling Level for MongoDB检索MongoDB的当前评测级别
Optional
options: CommandOperationOptionsOptional settings for the command命令的可选设置
Remove a user from a database从数据库中删除用户
The username to remove要删除的用户名
Optional
options: CommandOperationOptionsOptional settings for the command命令的可选设置
Rename a collection.重命名集合。
Name of current collection to rename要重命名的当前集合的名称
New name of of the collection集合的新名称
Optional
options: RenameOptionsOptional settings for the command命令的可选设置
This operation does not inherit options from the MongoClient.此操作不会继承MongoClient
的选项。
A low level cursor API providing basic driver functionality:提供基本驱动程序功能的低级游标API:
ReadPreference
The command that will start a cursor on the server.将在服务器上启动游标的命令。
Optional
options: RunCursorCommandOptionsConfigurations for running the command, bson options will apply to getMores运行命令的配置,bson选项将应用于getMores
Set the current profiling level of MongoDB设置MongoDB的当前评测级别
The new profiling level (off, slow_only, all).新的分析级别(关闭、慢速、全部)。
Optional
options: CommandOperationOptionsOptional settings for the command命令的可选设置
Get all the db statistics.获取所有数据库统计信息。
Optional
options: DbStatsOptionsOptional settings for the command命令的可选设置
Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this database. Will ignore all changes to system collections.创建一个新的变更流,监视此数据库中的新变更(插入、更新、替换、删除和无效)。将忽略对系统集合的所有更改。
Type of the data being detected by the change stream变更流检测到的数据类型
Type of the whole change stream document emitted发出的整个变更流文档的类型
An array of pipeline stages through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.一组管道阶段,通过这些阶段传递更改流文档。这允许筛选(使用$match
)和操作变更流文档。
Optional settings for the command命令的可选设置
watch() accepts two generic arguments for distinct use cases:watch()
为不同的用例接受两个泛型参数:
Generated using TypeDoc
The Db class is a class that represents a MongoDB Database.Db
类是一个表示MongoDB数据库的类。Example