0

Setup Information

One ConfigServer

mongod.exe --configsvr --dbpath C:\MongoDBCluster\ConfigSrv

--Mongos Server--

mongos.exe --configdb 10.133.1.130)

2 Shard Servers

mongod.exe --shardsvr --dbpath C:\MongoDBcluster\Server2\configdb --port 27020

mongod.exe --shardsvr --dbpath C:\MongoDBcluster\Server3\configdb --port 27021

Configured Sharding using mongos

mongos> sh.status()
--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("55dec7d254984cdf812cdf55")
}
  shards:
        {  "_id" : "shard0000",  "host" : "Server1:27020" }
        {  "_id" : "shard0001",  "host" : "Server2:27021" }
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                No recent migrations
  databases:
        {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
        {  "_id" : "demo1",  "partitioned" : true,  "primary" : "shard0001" }
                demo1.demo
                        shard key: { "_id" : 1 }
                        chunks:
                                shard0001       1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard0001 Timestamp(1, 0)

I have 2 problems

  1. When i try to check the sharding status from demo1 db on server1 i get below error

use demo1 switched to db demo1 sh.status() printShardingStatus: this db does not have sharding enabled. be sure you are connecting to a mongos from the shell and not to a mongod.

  1. I have inserted couple of records which did not get replicated to server2. what am i doing wrong?
1
  1. sh.status() can only be executed on your mongos. As you posted your "sharding status" with sh.status() in your question yourself. You can't do that on the separate shards.

  2. Sharding is for distributing your documents. For example documents ABC on shard0000 and documents DEF on shard0001. So Sharding is not Replication. If you want to replicate your documents then you need to look at 'How to setup a mongodb replica set' : http://docs.mongodb.org/master/tutorial/deploy-replica-set/

Update : a full answer you can find here : Difference between Sharding And Replication on MongoDB

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.