InterviewSolution
| 1. |
How is data synchronized from primary to other members in MongoDB replica sets? |
|
Answer» MongoDB applies database operations on the PRIMARY and then records the operations on the primary’s oplog. The secondary members then copy and apply these operations in an asynchronous process. For each operation, there is separate oplog entry. First, let’s check how many ROWS the query WOULD fetch by changing delete to find operation. db.sample.find( { state : "WA" } ) This will give all the rows with the state is WA. {"firstName" : "Arthur", "lastName" : "Aaronson", "state" : "WA", "city" : "SEATTLE", "likes" : [ "dogs", "cats" ] } {"firstName" : "Beth", "lastName" : "Barnes", "state" : "WA", "city" : "Richland", "likes" : [ "forest", "cats" ] } {"firstName" : "Dawn", "lastName" : "Davis", "state" : "WA", "city" : "Seattle", "likes" : [ "forest", "mountains" ] }Now Ideally delete should remove all matching rows but query says deleteOne. If the query would have said deleteMany then all the matching rows would have been deleted and there would be 3 oplog ENTRIES but deleteOne will remove first matching row. So 1 oplog entry will be generated with provided query |
|