I'm trying to execute a blocking call to db.collection.insert(List<DBObject>, WriteConcern)
method with the MongoDB java driver. No matter what I use in WriteConcern: SAFE
, FSYNC_SAFE
, FSYNCED
, ACKNOWLEDGED
, ... I can't grant the write has been performed...at least not the way I'm doing it right now. Check the code:
WriteResult result = collection.insert(list, WriteConcern.FSYNC_SAFE);
if (result.getN()> 0){
System.out.println("Alleluyah!");
return true;
}
From what I've read here, FSYNC_SAFE
, should be the way to go... The data is being written, but the call to result.getN()
is always zero. If there is no way to check if a write has been completed...
Why create the getN()
method in the first place?? Any idea of what I'm doing wrong? I do need to check this insert has been performed. I can query the collection and check, but it just looks overkill to me...
Thanks!