feat(mongodb): bson dumps and database backup/restore
This commit is contained in:
1 parent
ecc1135de3
commit
f5673ca0a1
54 files changed
+6355
-106
No files matched your search
@@ -101,26 +101,39 @@ GridFS 工作台用于管理 Bucket 和文件:
|
||||
|
||||
## 导入与导出
|
||||
|
||||
Collection 文档提供独立的 CSV/JSON 导入和 CSV/NDJSON 导出,和关系型 Table Import 不是同一条工作流。CSV 每一行生成一个文档,嵌套值保持嵌套,`$oid`、`$date` 等 Extended JSON 类型可以保留。
|
||||
Collection 文档提供独立的 CSV/JSON/NDJSON 与 BSON 导入导出,和关系型 Table Import 不是同一条工作流。CSV 每一行生成一个文档,嵌套值保持嵌套,BSON 备份保留原生 BSON 类型。
|
||||
|
||||
### 导入数据
|
||||
|
||||
1. 在集合上右键选择「导入数据」。
|
||||
2. 选择 `.csv`、`.json` 或 `.ndjson` 文件。桌面端读取本地路径,Web 端上传到临时文件。
|
||||
3. 对照预览调整编码、分隔符、表头、空值和类型策略。
|
||||
2. 先明确选择格式,再选择 `.csv`、`.json`、`.ndjson`/`.jsonl`、`.bson` 或 `.bson.gz` 文件。桌面端读取本地路径,Web 端上传到临时文件;更换文件不会覆盖已选择的格式。
|
||||
3. 对照预览检查数据。文本格式支持编码和类型设置,CSV 可逐列覆盖推断类型;BSON 导入不应用 CSV 文本转换。
|
||||
4. 确认以追加方式写入。重复 `_id` 会停止导入,已提交的批次不会回滚。
|
||||
|
||||
CSV 按 MongoDB Compass:首行表头,嵌套字段用点号路径(`address.city`),数组索引(`tags[0]`、`matrix[0][1]`),ObjectId 写成 24 位十六进制,日期为 ISO-8601,空单元格为 null。导入采样前 1000 行推断列类型;`_id` 的十六进制会还原为 ObjectId,`recognizeObjectIdHex` 可将此规则扩展到其他列。JSON/NDJSON 使用 Extended JSON(`$oid`、`$date`)。全部按字符串会把每个单元格当文本。
|
||||
|
||||
类型保真:`Double` 导出再导入会变为 `Decimal128`(十进制文本无损)。非 `_id` 的 ObjectId 字段会往返为 String,除非打开 `recognizeObjectIdHex`。小的 `Int64` 可能收窄为 `Int32`;ISO 日期格式的字符串会变为 `DateTime`。Extended JSON 类型(`$binary`、`$regularExpression`、`$timestamp`、`$minKey`、`$maxKey`、`$code`)通过 JSON 文本单元格往返。空数组 `[]` 和空对象 `{}` 往返正确。
|
||||
CSV 类型保真:`Double` 导出再导入会变为 `Decimal128`(十进制文本无损)。非 `_id` 的 ObjectId 字段会往返为 String,除非打开 `recognizeObjectIdHex`。小的 `Int64` 可能收窄为 `Int32`;ISO 日期格式的字符串会变为 `DateTime`。Extended JSON 类型(`$binary`、`$regularExpression`、`$timestamp`、`$minKey`、`$maxKey`、`$code`)通过 JSON 文本单元格往返。空数组 `[]` 和空对象 `{}` 往返正确。
|
||||
|
||||
首期限制:只支持追加(无清空或 upsert),无按字段类型覆盖,CSV 导出从前 10000 个文档发现字段(之后的字段会被静默丢弃;变化 schema 请改用 NDJSON),无 JSON 数组导出格式,不支持 Excel/GridFS/BSON 二进制导入,失败批次不会自动重试。
|
||||
集合导入限制:只支持追加(无清空或 upsert),CSV 导出从前 10000 个文档发现字段(之后的字段会被静默丢弃;变化 schema 请改用 NDJSON 或 BSON),无 JSON 数组导出格式,不支持 Excel/GridFS 导入,失败批次不会自动重试。集合级 BSON 导入只恢复文档,不恢复配套元数据和索引。
|
||||
|
||||
### 导出数据
|
||||
|
||||
- 在集合上右键选择「导出数据」,再选 CSV 或 NDJSON,会像表导出一样直接打开保存文件对话框。
|
||||
- 在集合上右键选择「导出数据」,再选 CSV、NDJSON、BSON 或 Gzip BSON,会像表导出一样直接打开保存文件对话框。
|
||||
- CSV 嵌套对象写为点号列(`address.city`),数组写为索引列(`tags[0]`、`tags[1]`)。NDJSON 每行一个规范 Extended JSON 文档。
|
||||
- 字段数超过 256 的 Collection 请改用 NDJSON。
|
||||
- 字段数超过 256 的 Collection 请改用 NDJSON 或 BSON。
|
||||
|
||||
### 数据库备份与恢复
|
||||
|
||||
使用 MongoDB 原生驱动时,在数据库节点右键选择「备份数据库」或「恢复数据库」。数据库备份包含选中集合、集合选项、索引和视图。
|
||||
|
||||
- 桌面端支持官方目录布局与 MongoDB archive 格式,均可使用 gzip。Web 端导出 archive 文件,恢复时支持 archive 或上传目录。
|
||||
- 目录备份包含 `<数据库>/<集合>.bson` 和 `.metadata.json`,或对应的 `.gz` 文件。MongoDB archive 是独立的流式格式,不是 ZIP 或 tar。
|
||||
- 格式与 gzip 选项需明确选择。目录恢复的「读取备份」只读取清单和元数据;确认源库、目标库和集合后,才上传选中的数据文件。
|
||||
- 恢复按单遍流式读取和写入进行。可选的 `objcheck` 默认关闭,开启后在同一遍读取中逐文档校验;BSON 边界、gzip 完整性和 archive 校验和检查始终保留。
|
||||
- 默认追加写入。「恢复前删除选中的目标同名集合」只删除并重建这些集合。已有 `_id` 可能导致 `E11000`;失败或取消不会回滚此前的写入。
|
||||
- Web 上传复用服务端 `DBX_MAX_UPLOAD_MB` 配置。桌面端直接读取本地文件,无需 HTTP 上传。
|
||||
|
||||
上述格式可与官方 `mongodump`/`mongorestore` 对支持的集合双向互通。本流程不提供 oplog 回放、时间点一致性保证、UUID 保留,也不处理内部数据库、时间序列集合和加密集合;这些场景请使用官方工具。
|
||||
|
||||
如果只需要当前可见选择,仍可从表格复制当前文档、选中文档或字段值为普通 JSON 或 Extended JSON。
|
||||
|
||||
|
||||
@@ -101,26 +101,39 @@ Dropping a bucket removes its files and chunks. Verify the bucket name and backu
|
||||
|
||||
## Import and Export
|
||||
|
||||
Collection documents have a dedicated CSV/JSON import and CSV/NDJSON export workflow. This is separate from relational Table Import: each CSV row becomes a document, nested values stay nested, and Extended JSON types such as `$oid` and `$date` can be preserved.
|
||||
Collection documents have dedicated CSV/JSON/NDJSON and BSON import/export workflows. This is separate from relational Table Import: each CSV row becomes a document, nested values stay nested, and BSON dumps preserve native BSON types.
|
||||
|
||||
### Import data
|
||||
|
||||
1. Right-click a collection and choose **Import data**.
|
||||
2. Select a `.csv`, `.json`, or `.ndjson` file. Desktop reads the local path; Web uploads it to a temporary server file.
|
||||
3. Review encoding, delimiter, header, empty-value, and type settings against the preview.
|
||||
2. Choose the format explicitly, then select a `.csv`, `.json`, `.ndjson`/`.jsonl`, `.bson`, or `.bson.gz` file. Desktop reads the local path; Web uploads it to a temporary server file. Changing the file does not override the selected format.
|
||||
3. Review the preview. Text formats expose encoding and type settings; CSV supports per-column type overrides. BSON imports do not apply CSV text conversions.
|
||||
4. Confirm append-only insert. Duplicate `_id` values stop the import. Batches that already committed are not rolled back.
|
||||
|
||||
CSV follows MongoDB Compass: a header row, nested fields as dotted paths (`address.city`), array indices (`tags[0]`, `matrix[0][1]`), ObjectId as 24-character hex, dates as ISO-8601, and empty cells as null. Import samples the first 1000 rows to infer column types; `_id` hex is restored as ObjectId, and `recognizeObjectIdHex` extends this to other columns. JSON/NDJSON use Extended JSON (`$oid`, `$date`). All strings keeps every cell as text.
|
||||
|
||||
Type fidelity: `Double` exports and reimports as `Decimal128` (lossless for decimal text). Non-`_id` ObjectId fields round-trip as String unless `recognizeObjectIdHex` is on. Small `Int64` may narrow to `Int32`; ISO-date-looking strings become `DateTime`. Extended JSON types (`$binary`, `$regularExpression`, `$timestamp`, `$minKey`, `$maxKey`, `$code`) round-trip through JSON-text cells. Empty array `[]` and empty object `{}` round-trip correctly.
|
||||
CSV type fidelity: `Double` exports and reimports as `Decimal128` (lossless for decimal text). Non-`_id` ObjectId fields round-trip as String unless `recognizeObjectIdHex` is on. Small `Int64` may narrow to `Int32`; ISO-date-looking strings become `DateTime`. Extended JSON types (`$binary`, `$regularExpression`, `$timestamp`, `$minKey`, `$maxKey`, `$code`) round-trip through JSON-text cells. Empty array `[]` and empty object `{}` round-trip correctly.
|
||||
|
||||
First-release limits: append only (no truncate or upsert), no per-field type override, CSV export discovers fields from the first 10000 documents (later fields are silently dropped; use NDJSON for variable schemas), no JSON-array export format, no Excel/GridFS/BSON binary import, and no automatic retry of failed batches.
|
||||
Collection-import limits: append only (no truncate or upsert), CSV export discovers fields from the first 10000 documents (later fields are silently dropped; use NDJSON or BSON for variable schemas), no JSON-array export format, no Excel/GridFS import, and no automatic retry of failed batches. Collection-level BSON import restores documents only, not the companion metadata or indexes.
|
||||
|
||||
### Export data
|
||||
|
||||
- Right-click a collection and choose **Export data**, then CSV or NDJSON. This opens the save-file dialog immediately, the same as table export.
|
||||
- Right-click a collection and choose **Export data**, then CSV, NDJSON, BSON, or gzip BSON. This opens the save-file dialog immediately, the same as table export.
|
||||
- CSV writes nested objects as dotted columns (`address.city`) and arrays as indexed columns (`tags[0]`, `tags[1]`). NDJSON writes one canonical Extended JSON document per line.
|
||||
- Collections with more than 256 distinct fields should use NDJSON.
|
||||
- Collections with more than 256 distinct fields should use NDJSON or BSON.
|
||||
|
||||
### Database backups
|
||||
|
||||
With the native MongoDB driver, right-click a database and choose **Back up database** or **Restore database**. Database backups include selected collections, collection options, indexes and views.
|
||||
|
||||
- Desktop supports the official dump directory layout and MongoDB archive format, optionally gzip-compressed. Web exports archive files and restores either archives or uploaded directories.
|
||||
- A dump directory contains `<database>/<collection>.bson` and `.metadata.json`, or their `.gz` variants. MongoDB archive is a separate stream format, not ZIP or tar.
|
||||
- Choose the format and gzip option explicitly. For directory restore, **Read backup** reads the catalog and metadata; selected data files are uploaded only after confirming the source database, target database and collections.
|
||||
- Restore reads and writes data in one pass. Optional `objcheck` validates each BSON document in that same pass and defaults off. Framing, gzip and archive checksum checks remain enabled.
|
||||
- Restore appends by default. **Drop selected target collections before restoring** deletes and recreates only those collections. Existing `_id` values can cause `E11000`; failures or cancellation do not roll back earlier writes.
|
||||
- Web uploads use the shared `DBX_MAX_UPLOAD_MB` server setting. Desktop reads local files without an HTTP upload.
|
||||
|
||||
These formats interoperate with `mongodump`/`mongorestore` for supported collections. Oplog replay, point-in-time guarantees, UUID preservation, internal databases, time-series collections and encrypted collections are outside this workflow; use the official tools for those cases.
|
||||
|
||||
Copy the current document, selected documents, or field values as plain JSON or Extended JSON from the grid when you only need the visible selection.
|
||||
|
||||
|
||||
Reference in new issue
Block a user