14 Mayıs 2019 Salı

Mongodb Change secondary priority(avoid becoming primary)




Hi,

You may have mongodb replica set and also you may want to set ones to avoid becoming primary.

For example we have 1 replica set. 1 primary(Roma),1 local secondary(Roma) and 1 remote secondary(Milano). If there is a problem with primary Roma or Milano may be primary after elections.But we want that Milano site is disaster site and it shouldn't be in elections.

For this request,our need to set priority to 0



1)cfg = rs.conf()

2)cfg.members[2].priority = 0

3) rs.reconfig(cfg)



Attention:

cfg.members[2].priority------------------>We set 2nd member priority,it may be different in your replica set


MongoDB is pretty:)

Failed: necodb.contents: error creating collection necodb.contents: error running create command: BSON field 'OperationSessionInfo.create' is a duplicate field



Hi,

I have a migration project.We will migrate from mongo 2.4.12 to mongo 4.0.6.

We are using community version. So  we have to choose mongodump method.

There is no error while exporting data.But import is failed.


Problem:
-----------

##############################################################################
Failed: necodb.contents: error creating collection necodb.contents: error running create command: BSON field 'OperationSessionInfo.create' is a duplicate field


##############################################################################

Solution:
-----------

1)use 2.4.12 mongobackup on the 2.4 database

mongodump --db necodb--out /mondirec/backup/

2)delete or move all .json files from the outputted dump directory

3)use 4.0.6 mongorestore on the remaining .bson files

mongorestore --db necodb --drop /mondirec/backup/necodb




Thanks for dba.exchange.com for this solution.


Reference:

https://dba.stackexchange.com/questions/201827/failed-to-import-a-mongodb-database-with-duplicate-fields