pkdone/minikube-mongodb-demo

Example replication test command block causes unexpected errors

Closed this issue · 0 comments

In 1.3.1 Replication Test there is the following code block:

$ kubectl exec -it mongod-1 -c mongod-container bash
$ mongo
> db.getSiblingDB('admin').auth("main_admin", "abc123");
> db.setSlaveOk(1);
> use test;
> db.testcoll.find();

Following this block results in an error, which seems to point at an incorrect ordering of commands.

MainRepSet:SECONDARY> db.getSiblingDB('admin').auth('admin', 'password');
1
MainRepSet:SECONDARY> db.setSlaveOk(1);
MainRepSet:SECONDARY> use test;
switched to db test
MainRepSet:SECONDARY> db.testcoll.find();
Error: error: {
	"operationTime" : Timestamp(1523998362, 1),
	"ok" : 0,
	"errmsg" : "not master and slaveOk=false",
	"code" : 13435,
	"codeName" : "NotMasterNoSlaveOk",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1523998362, 1),
		"signature" : {
			"hash" : BinData(0,"AD2neVaDyfgPsQSzueLs+HYtv4w="),
			"keyId" : NumberLong("6545521577759342593")
		}
	}
}

Running the db.setSlaveOk(1); after the use test; allows it to work as expected:

MainRepSet:SECONDARY> db.setSlaveOk(1);
MainRepSet:SECONDARY> db.testcoll.find();
{ "_id" : ObjectId("5ad65e6cad27b03ddadf87c9"), "a" : 1 }
{ "_id" : ObjectId("5ad65e71ad27b03ddadf87ca"), "b" : 2 }

Before submitting a pull request reordering the commands I wanted to check that this wasn't simply user error, or an issue due to versioning of anything.

This deployment was built using the yaml file in the repo, so the current mongo image being pulled contains the following versions:

root@mongod-1:/# mongo --version
MongoDB shell version v3.6.3
git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: debian81
    distarch: x86_64
    target_arch: x86_64
root@mongod-1:/# mongod --version
db version v3.6.3
git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: debian81
    distarch: x86_64
    target_arch: x86_64