gpt4 book ai didi

json - mongoimport 无法从 JSON 文件加载 $uuid 字段

转载 作者:可可西里 更新时间:2023-11-01 10:50:10 26 4
gpt4 key购买 nike

我想使用 mongoimport 加载包含 UUID 字段的 JSON 文件。

创建 JSON 文件的程序会像这样序列化 UUIDS:

{ "_id": {"$uuid": "9ab62b5e-f34a-3854-b8bf-df7ee0102229"}, "foo": "bar" }

在我要导入的集合中,文档 UUID 以二进制格式表示:

{ "_id" : BinData(3,"eT/WZXnp96m5uHOpApFSmg=="), "foo" : "bar"}

mongoimport 不喜欢 $uuid 位,并失败

$ cat foo.json|  mongoimport -h 127.0.0.1 -d mydb --collection mycollection
2017-01-30T23:46:05.060+0100 connected to: 127.0.0.1
2017-01-30T23:46:05.079+0100 error inserting documents: $uuid is not valid for storage.
2017-01-30T23:46:05.079+0100 imported 0 documents

关于如何解决这个问题的任何想法

最佳答案

根据 mongoimport 文档

Warning

Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.

可以理解的是,UUID 转换的二进制数据不属于有效的 JSON 数据类型,因此它失败了,您可以尝试 mongodump,它更可靠。

关于json - mongoimport 无法从 JSON 文件加载 $uuid 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41946856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com