gpt4 book ai didi

java - 无法将 BasicDBObject 转换为 [B

转载 作者:可可西里 更新时间:2023-11-01 09:51:22 25 4
gpt4 key购买 nike

我在 mongodb 数据库中有以下 gridfs:

db.outputFs.files.find()

{ "_id" : ObjectId("000000000000000000000001"), "chunkSize" : 261120, "length" : 232, "md5" : "42290309186cc5420acff293b92ae21d", "filename" : "/tmp/outputFs-01.tmp", "contentType" : null, "uploadDate" : ISODate("2015-04-13T13:50:48.259Z"), "aliases" : null, "metadata" : { "estado" : "FICHERO_PDTE_ENVIO", "dataDate" : "20141122", "inputOutputFs" : "output", "gridFileCompression" : "bzip2", "fileType" : "OUTPUT-TEST1", "filePath" : "/tmp/outputFs-01.tmp", "sourceParticipant" : "0100", "destinationParticipant" : "REE", "exportFileName" : "F1_0100_20141122_20150219.0", "processed" : "false", "fileMD5" : "4276e61a4b63d3d1d1b77e27e792bd13", "version" : 0 } }

{ "_id" : ObjectId("000000000000000000000002"), "chunkSize" : 261120, "length" : 232, "md5" : "42290309186cc5420acff293b92ae21d", "filename" : "/tmp/outputFs-02.tmp", "contentType" : null, "uploadDate" : ISODate("2015-04-13T13:50:48.259Z"), "aliases" : null, "metadata" : { "estado" : "FICHERO_ENVIADO_OK", "fechaEnvio" : ISODate("2015-04-13T13:50:48.259Z"), "dataDate" : "20141123", "inputOutputFs" : "output", "gridFileCompression" : "bzip2", "fileType" : "OUTPUT-TEST2", "filePath" : "/tmp/outputFs-02.tmp", "sourceParticipant" : "0100", "destinationParticipant" : "REE", "exportFileName" : "F1_0100_20141123_20150220.0", "processed" : "false", "fileMD5" : "4276e61a4b63d3d1d1b77e27e792bd13", "version" : 0 } }



db.outputFs.chunks.find()

{ "_id" : ObjectId("000000000000000000000001"), "files_id" : ObjectId("000000000000000000000001"), "n" : 0, "data" : { "$type" : 0, "$binary" : "QlpoOTFBWSZTWZSBQ/YABX5cAAAYQAH/+CAAMAFWA0NqptIb9UgAZ6qowAAFKSaJpGhk8ssmVlk7AAAALZtZZOf0vr859OqflcIs461Dm1skcSOpGpHMuu5HcsJG0j5I9PiR4kaRvvjWskfsVMkZVLxI3uRy/pGTqRj7VmMyTOBfUtb561rwkf0j09+Zbkd+cs1I77861xI7pypvfOt1v5DmR1I51nW7XGdaluRnGZjMzJMzOZGpHnrfGM56+/fnGPVVVVVqqpVVWxCSxCTSAEMkZI3IyqXuqXyRuR/i7kinChISkCh+wA==" } }

{ "_id" : ObjectId("000000000000000000000002"), "files_id" : ObjectId("000000000000000000000002"), "n" : 0, "data" : { "$type" : 0, "$binary" : "QlpoOTFBWSZTWZSBQ/YABX5cAAAYQAH/+CAAMAFWA0NqptIb9UgAZ6qowAAFKSaJpGhk8ssmVlk7AAAALZtZZOf0vr859OqflcIs461Dm1skcSOpGpHMuu5HcsJG0j5I9PiR4kaRvvjWskfsVMkZVLxI3uRy/pGTqRj7VmMyTOBfUtb561rwkf0j09+Zbkd+cs1I77861xI7pypvfOt1v5DmR1I51nW7XGdaluRnGZjMzJMzOZGpHnrfGM56+/fnGPVVVVVqqpVVWxCSxCTSAEMkZI3IyqXuqXyRuR/i7kinChISkCh+wA==" } }

当我尝试使用 Spring Data 或什至 MongoChef(两个 Java 客户端)将其作为文件检索时,我收到以下错误:

com.mongodb.BasicDBObject cannot be cast to [B

这些集合是按原样手动导入的,没有使用 MongoChefmongofiles,我不知道这个错误可能来自哪里。

最佳答案

GridFS 规范要求 chunks 集合中有一个名为 dataBinary 字段。但是,您的 outputFs.chunks 不符合此条件。

这里的data 字段不是Binary BSON 数据类型,而是一个常规文档,它恰好有两个字段$type$数据

mongoimport 将为以下格式的 JSON 条目创建二进制字段。请注意,字段顺序对 mongoimport 很重要。

{
"$binary" : ...
"$type" : ...
}

您的示例交换了 $type$binary 字段。

更新您的 JSON 文件并再次导入您的 outputFs.chunksmongoimport 将创建有效的二进制字段,您将能够使用其他 MongoDB 工具来处理 GridFS。

关于java - 无法将 BasicDBObject 转换为 [B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29794736/

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