Hi ,
With following read and write concerns,
db.adminCommand({
"setDefaultRWConcern" : 1,
"defaultWriteConcern" : {
"w" : 2
},
"defaultReadConcern" : { "level" : "majority" }
})
And knowing little more on readConcerns, we come to conclusion that why I faced these issues. I just mentioned them below with their cause.
Issue 1 :
As I have mentioned my writeConcern as ==> {w:2} data might not have been durable by the time am reading it through readConcern of ==> “majority”,
May be because of that I was not getting data even from primary node
Issue 2 :
Same thing applies to Secondary as well, with writeConcern as ==> {w:2} and read concern as ==>. “majority” you are trying to read durable data from secondary.
By the time that you are trying to read, it might not have been durable in the secondary.
With this , readConcern also plays a major role while reading the data. In our case, as we are not using any Transaction for storing data, and speed is main concern,
{readConcern: ‘local’} makes more sense for us. With this we get data faster as we are not looking at any fail over cases.
Hope this helps.
Thanks
Gangadhar M