0

Colleagues, I'm using Mongo of v2.2 and java Mongo driver 2.9.0,

Some business logic creates approximately 25 threads and each thread creates 150 files on GridFS. Approximately 20 files per 1000 are not return correct getId() so result is null. I think (correct me if I'm wrong) it is correct behavior in perspective of throughput. But I really need this id. For regular DBCollection I would set WriteConcern.FSYNC_SAFE, but I cannot see if exist method setWriteConcern for GridFS. Have you some ideas how to force files be flushed ?

Dewfy
  • 23,277
  • 13
  • 73
  • 121

1 Answers1

0

Looking at driver code in GridFS.java:

_filesCollection = _db.getCollection( _bucketName + ".files" );

I can resolve collection with the same name after creation of GridFS, so my code with setting write concern looks like:

_fs = new GridFS(_db, "MyBucketName");
DBCollection col = _db.getCollection( "MyBucketName" + ".files" );
col.setWriteConcern(WriteConcern.SAFE);

After starting tests I can see that all files are successfully returns correct id.

Dewfy
  • 23,277
  • 13
  • 73
  • 121
  • is this the appropriate thing to do in order to force a majority or w=N write concern on gridfs as it seems a bit hacky? – simbo1905 May 31 '13 at 05:04
  • @simbo1905 it is not a hack - since all methods there are public. What just missed from 10gen developers side is a method that renders name of GridFS collection. But this name is not a secret (and even subject of changes) - you can explore it from database console. – Dewfy May 31 '13 at 07:58