GridFS support in MongoAPI of Azure DocumentDB

雨燕双飞 提交于 2019-12-18 17:26:16

问题


I am using the MongoDB API for DocumentDB via the GridFsTemplate from springdata in JAVA.

I am getting an error when trying to use the GridFS part of MongoDB to manage large files.

I am able to create a file (I think) and find its metadata, but I cannot retrieve the file contents. The following error is returned:

Error: error: {
    "_t" : "OKMongoResponse",
    "ok" : 0,
    "code" : 8,
    "errmsg" : "The value '/media/7hsUAJOI2QsBAAAAAAAAAEeWwrcB' specified  for query '$resolveFor' is invalid.\r\nActivityId: a68945e8-0000-0000-0000-000000000000",
    "$err" : "The value '/media/7hsUAJOI2QsBAAAAAAAAAEeWwrcB' specified  for query '$resolveFor' is invalid.\r\nActivityId: a68945e8-0000-0000-0000-000000000000"
}

I get the same error using Robomongo and trying to inspect the fs.chunks collection.

The reason I say that I think I can create the collection is because using the Browse functionality in Azure's web interface, it seems that fs.chunks has only one record instead of many chunks. So maybe the storing is the issue.

All of this works fine if using the standard MongoDB.

This is the code to save the file which completes without error.

gridFsTemplate.store( content, filename, contentType, metadata );

And here is the code to find it and get the contents

//this works
GridFSDBFile data = gridFsTemplate.findOne( query );
ByteArrayOutputStream out = new ByteArrayOutputStream();
if ( data != null )
{
    //this results in Exception with the same message as the error above
    data.writeTo( out );
}

回答1:


There is a third party blog which introduce the differences between DocumentDB and MongoDB, please note the section Binary Large Object (BLOB) Storage. And now, Azure DocumentDB has been extended & upgraded as Azure Cosmos DB which is multi-model database which includes document, key-value, graph, not BLOB. So I think you should only consider to use DocumentDB or Cosmos DB via MongoDB API as a JSON store system. If you want to use storage for files, please consider for Azure Blob storage.

Hope it helps.



来源:https://stackoverflow.com/questions/43901158/gridfs-support-in-mongoapi-of-azure-documentdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!