I want to keep MongoDB and Solr in sync. The mongodb-connector (python) is the tool I want to use to do that. Now a replica set in mongodb is required (see ReadMe), but I don't want (and can) setup a set/instance.

So can I have a replica set setup with only the primary and without secondaries? Means: A replica set setup with only one instance? And how does this

Meanwhile I found a solution:

  1. Add in the config-File following:
    • replSet=rs0 (name is variable) (necessary because starting mongod with replSet option didn't work)
    • oplogSize=[MemSize]
  2. Start mongodb-instance:
    • sudo /etc/init.d/mongod start
    • mongo
  3. Set replicaset:
    • rs.initiate({"_id" : "rs0","version" : 1,"members" : [{"_id" : 0,"host" : "localhost:27017"}]})
    • Check with rs.status()

In mongodb 3.2 "replSet" is changed to "replSetName" https://docs.mongodb.com/v3.2/tutorial/upgrade-config-servers-to-replica-set/


You can start a single node replica set by starting the mongod with the replSet argument/config option, that is all that is required. It takes a name argument, which will then function as the name of the replica set in question. Once you have done that, you simply run rs.initiate() from the shell when connected to the node (this is only needed once).

This is described in detail here:


To stay with just a single node, simply do not follow the "Expanding the set" instructions.

| improve this answer | |
  • That didn't work. Meanwhile, I found a solution which is similar to yours: (edit will come soon.) – MUmla Nov 27 '13 at 10:22
  • Odd, because I have done this maybe.......30 times when testing without a problem, and those are the official docs too – Adam C Nov 27 '13 at 10:40
  • (See my solution in the question above.) – MUmla Nov 29 '13 at 10:02
  • your solution is identical to the one I provided, all you did was fill in variable names - if you do not specify an initial replica set name, it is filled in by default as the current process. Similarly oplogSize is optional - if you do not specify it, it will default to 5% of free space. Similarly, none of the other commands are optional and are not required to provision an oplog or set up a single node replica set. – Adam C Nov 29 '13 at 20:16

Here's what I did in a similar process for Elasticsearch on a Mac using Brew:

Note: as new daemons are started, switch to new terminals

ElasticSearch (after 'brew install elasticsearch'):

$ elasticsearch #start es daemon on port 9200

MongoDB just outside the 'data' folder [or other database location] (and after 'brew install mongodb' and 'pip install mongo-connector' and 'pip install elastic2-doc-manager'):

$ mongod --dbpath data --replSet "rs0" #create replica set on port 27017

$ mongo #initiate replica set

> rs.initiate({"_id" : "rs0","version" : 1,"members" : [{"_id" : 0,"host" : "localhost:27017"}]})
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.