简体   繁体   中英

initiate mongodb replica set

I am running the following in a script to automate the initiation of a replica set:

var cfg = { _id: 'rs0',
    members: [
        { _id: 0, host: '192.168.1.46:27017'},
        { _id: 1, host: '192.168.1.51:27017'},
        { _id: 2, host: '192.168.1.48:27017'}
    ]
};

var error = rs.initiate(cfg);
printjson(error);

However I am getting :

{ "ok" : 0, "errmsg" : "Missing expected field \"version\"", "code" : 93 }

After I run the script and am not sure why.

I have tried running the script locally as well using the following:

mongo 192.168.1.46:27017 /opt/scripts/initreplset.js

I am using mongodb v3.2.

I'm having the same problem now, probably is something quite new, anyway it seems that the version field is now mandatory.

From the official documentation:

version Type: int

An incrementing number used to distinguish revisions of the replica set configuration object from previous iterations of the configuration.

So probably you just need to add this number. Ie:

{
   "_id" : "rs0",
   "version" : 1,
   "members" : [
      {
         "_id" : 1,
         "host" : "mongodb0.example.net:27017"
      }
   ]
}

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