对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

插入文档

重要

不允许在 MongoDB Compass Readonly Edition 中插入文档。

Compass 提供以下模式视图,用于将文档插入到您的集合中:

shell 语法模式
写入或粘贴文档使用 MongoDB shell 语法,其允许未引用的字段名称和类型构造函数,例如 ObjectId() 和 ISODate()。使用此模式可将多个文档作为一个数组同时插入。
Field-by-Field Editor
选择每个插入文档的单个字段值和类型。此模式仅支持一次插入一个文档。
JSON Mode
Write or paste documents in Extended JSON format, which requires quoted field names and represents BSON types as wrappers such as {"$oid": "..."}. Use this mode to insert multiple documents at once as an array.

要将文档插入到集合中,请选择与所选视图模式相对应的标签页:

1

在下拉菜单中单击 Insert Document(复制视图)。

插入按钮
点击放大

或者,您可以右键单击查询栏或其周围的空格,然后从下拉菜单中选择 Insert document...。

2

In the Insert Document modal, click the icon to use Shell Syntax mode to insert documents into your collection.

Shell Syntax 模式是默认视图。

3

在 MongoDB shell 语法中,键入或粘贴要插入到集合中的文档。要插入多个文档,请输入以逗号分隔的文档数组。

例子

以下示例将单个文档插入到集合中。字段名称不加引号,_id、copies 和 lastCheckedOut 值使用 ObjectId()、NumberInt() 和 ISODate() 类型构造函数,而不是 Extended JSON 类型包装器:

{
_id: ObjectId('507f1f77bcf86cd799439011'),
title: 'The Odyssey',
author: 'Homer',
copies: NumberInt('10'),
lastCheckedOut: ISODate('2025-03-14T09:30:00Z')
}

注意

If you do not specify an _id value in your document, Compass automatically generates an ObjectId for the _id field.

4
给本页内容打分

在此页面上