Reputation: 975
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.
Upvotes: 1
Views: 2170
Reputation: 4234
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. I.e.:
{
"_id" : "rs0",
"version" : 1,
"members" : [
{
"_id" : 1,
"host" : "mongodb0.example.net:27017"
}
]
}
Upvotes: 7