On this page本页内容
MongoDB for VS Code is currently available as a Preview in the Visual Studio Marketplace.MongoDB for VS Code目前在Visual Studio Marketplace中作为预览版提供。The product, its features, and the corresponding documentation may change during the Preview stage.在预览阶段,产品及其相应的功能可能会发生变化。
Once you connect to your deployment using MongoDB for VS Code, use the left navigation to:使用MongoDB for VS Code连接到部署后,请使用左侧导航:
If your deployment requires authentication, your database user privileges may affect the actions you can perform using MongoDB for VS Code.如果部署需要身份验证,则数据库用户权限可能会影响使用MongoDB for VS Code执行的操作。
When you expand an active connection, MongoDB for VS Code shows the databases in that deployment.展开活动连接时,MongoDB for VS Code将显示该部署中的数据库。Click a database to view the collections it contains.单击数据库以查看它包含的集合。
Click a collection to view its documents, schema, and indexes.单击集合可查看其文档、架构和索引。
When you expand a collection, MongoDB for VS Code displays that collection's document count next to the Documents label in the navigation panel.展开集合时,MongoDB for VS Code会在导航面板的“文档”标签旁边显示该集合的文档计数。
When you expand a collection's documents, MongoDB for VS Code lists the 当您展开集合的文档时,MongoDB for VS Code会列出集合中每个文档的_id
of each document in the collection._id
。Click an 单击某个_id
value to open that document in VS Code and view its contents._id
值以在VS Code中打开该文档并查看其内容。
You cannot open a single document within a read-only view.不能在只读视图中打开单个文档。
Alternatively, right-click a collection and click View Documents to view all of the collection's documents in an array.或者,右键单击某个集合,然后单击查看文档以查看数组中该集合的所有文档。
Opening collection documents provides a read-only view of your data.打开收集文档提供数据的只读视图。To modify your data using MongoDB for VS Code, use a JavaScript Playground or launch a shell by right-clicking your active deployment in the MongoDB view in the Activity Bar.要使用MongoDB for VS Code修改数据,请使用JavaScript演练场,或者通过右键单击活动栏中MongoDB视图中的活动部署来启动shell。
You can open a JavaScript Playground pre-configured to search a collection by hovering over the Documents label in the navigation panel and clicking the icon that appears.通过将鼠标悬停在导航面板中的文档标签上并单击出现的图标,可以打开预先配置为搜索集合的JavaScript演练场。
Your collection's schema defines the fields and data types within the collection.集合的架构定义了集合中的字段和数据类型。Due to MongoDB's flexible schema model, different documents in a collection may contain different fields, and data types may vary within a field.由于MongoDB的灵活模式模型,集合中的不同文档可能包含不同的字段,并且字段内的数据类型也可能不同。MongoDB can enforce schema validation to ensure your collection documents have the same shape.MongoDB可以强制架构验证,以确保集合文档具有相同的形状。
When you expand a collection's schema, MongoDB for VS Code lists the fields which appear in that collection's documents.展开集合的架构时,MongoDB for VS Code会列出出现在该集合文档中的字段。If a field exists in all documents and its type is consistent throughout the collection, MongoDB for VS Code displays an icon indicating that field's data type.如果一个字段存在于所有文档中,并且其类型在整个集合中都是一致的,那么MongoDB for VS Code会显示一个图标,指示该字段的数据类型。Hover over the field name for a text description of the field's data type.将鼠标悬停在字段名上,以获取字段数据类型的文本说明。
Your collections's indexes are listed under the Indexes heading.您的收藏和索引列在索引标题下。When you expand an index, each index key appears with an icon designating its type.展开索引时,每个索引键都会显示一个图标,指示其类型。Index key types include:索引键类型包括:
You can open a MongoDB Playground pre-configured to create an index by hovering over the Indexes label in the navigation panel and clicking the icon that appears.您可以将鼠标悬停在导航面板中的索引标签上,然后单击出现的图标,打开预先配置为创建索引的MongoDB演练场。
For more information about MongoDB indexes, see the documentation in the server manual.有关MongoDB索引的更多信息,请参阅服务器手册中的文档。
When you create a new database, you must populate it with an initial collection.创建新数据库时,必须使用初始集合填充它。
To create a new database:若要创建新数据库:
To create a new collection:若要创建新集合:
Dropping data from MongoDB is an irreversible process.从MongoDB删除数据是一个不可逆的过程。Take caution to only drop data you are sure you want to delete, and backup your data as necessary.小心只删除您确定要删除的数据,并根据需要备份数据。
Dropping a database also drops all collections and documents within that database.删除数据库也会删除该数据库中的所有集合和文档。
To drop a database or collection:删除数据库或集合:
You can refresh a deployment, database, or collection at any time to re-query your deployment and populate MongoDB for VS Code with the most up-to-date data.您可以随时刷新部署、数据库或集合,以重新查询部署并使用最新数据填充MongoDB for VS Code。
To refresh:若要刷新: