简体   繁体   中英

Assign WriteConcern to mongo file system

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM