sharding - MongoDB routes all data to one server in a shard cluster -


I first set up a MongoDB push cluster on windows, as explained here:

I used the following scripts to get config server, mongos instance and Mongo data server.

  function get-cnfgServerObj ($ port, $ path) {$ firstCnfgSrv = New-Object PSObject $ firstCnfgSrv | Add-member noteparty -name port-value $ port $ firstCnfgSrv | Add-member nodeproperty -name path-value $ path return $ firstCnfgSrv; } $ Mongodpath = ".. \ mongod.exe" $ mongosPath = ".. \ mongos.exe" $ cnfg server = @ ((get-cnfgServerObj -port 20001 -PAT ".. \ data \ configdb20001"), (Received -CnfgServerObj -port 20002-path ".. \ data \ configdb20002"), (get-cnfgServerObj -port 20003 -ppt ".. \ data \ configdb20003")) $ dataServer = @ ((get-cnfgServerObj -port 27001 - Path ".. \ data \ shdb1"), (get-cnfgServerObj -port 27002 -ppt ".. \ data \ shdb2")) #Mango Config Server First Make $ cnfgServers | foreach {if ((test-path $ _ path) -a $ false) {new object-path $ _ Path-type type directory} $ args = "--configsvr - dbpath $ ($ _ path) - -port $ ($ _ port)" start-processing $ mongodPath $ args -windowstyle Normal} #Mongo Make server $ data server. foreach {if ((test-path $ _ path) -a $ false) {new object-path $ _ Path-ins type directory} $ args = "--dbpath $ ($ _ path) --port $ ($ _ port)" start-processing $ mongodpath $ args -windowstyle Normal} #mongos create instance $ mongosArgs = "- -configdb localhost: 20001, localhost: 20002, localhost: 20003 "Start-process $ mongosPath $ mongosArgs - WindowStyle General   

After running the above script, I'm connected to the Mongoose instance: / P>

  mongo --host localhost --port 27017   

Later, I added shards and sharding enabled on database and archive Add the server as shards sh.addShard ("localhost: 27001"): sh.addShard ("localhost: 27002") // 'foo' db sh.enableSharding (" Foo ") // 'foo' database sh.shardCollection (" foo.testData "," x ") Finally, I run the following comments inside the Mongo shell (which is related to the Mongol example):

   

code> use for foo / / init data (var i = 1; i & lt; = 2500; i ++) db .testData.insert ({x: i})

Later, I connected to one of my data servers:

  mongo --host is local When I try to see the count of documents inside the test data collection, I saw that this number is 2500, which reflects the count of all the documents:   

/ P>

  Usage foo db.testData.count ()   

Just the data is not loaded in all the shards, what am I doing wrong here?

Edit:

here ("535673272850501ad810ff51")} shards: {"_id": "shard0000", "host", "slash" Database: {"_id": "admin", "" fir "," partitioned ": true" "" ":" localhost: 27001 "} {" _id ":" shard0001 "," host ":" localhost: 27002 "} database: {"" "" "" "" "" "", "Primary": "config"} {"_id": "test", " Foo.testData shard key: {"x": 1, "_id": 1} chunks: shard0001 1, "shard0000": false, "primary": "shard0000"} {"_id", "primary": "shard 0000"} Shard0000 1 {"x": {"$ minKey": 1}, "_id": {"$ MinKey": 1}} - - & gt; & gt; {"X": 1, "_id": ObjectId ( "53567411cb144434eb53f08d"}}: shard0001 Tim Estamp (2, 0) {"x": 1, "_id": ObjectId ("53567411cb144434eb53f08d")} ->> "{": " {"$ MaxKey": 1}, "_id": {"$ maxKey": 1}} at: shard0000 Tim Estamp (2, 1)

I assume that your trash cluster is properly setup and you are connecting it correctly (although I do not know if you have a Mongod and mongos No, maybe you are inserting mongod and mongos ?) < P> One reason for the lack of balance is that your x, _id key is non-linear, a linear category which is the lowest Is going to the highest, as it writes, starting from the beginning of the border will begin.

Since the MongoDB is based on the sharding range, it will actually place the entire range on the first shard, unless it really is not suitable to balance it: which is not the case yet.

Basically it is a way to decide that you select your shard key: wisely

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -