jbteros
jbteros

Reputation: 43

GridFS support in MongoAPI of Azure DocumentDB

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 );
}

Upvotes: 4

Views: 2701

Answers (1)

Peter Pan
Peter Pan

Reputation: 24138

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.

Upvotes: 1

Related Questions