开发者

Sharding in MongoDB using C# driver

开发者 https://www.devze.com 2023-03-29 23:25 出处:网络
I try to experiment with sharding and make a sample configuration: the simplest one for two shards. Here is the code from bat files:

I try to experiment with sharding and make a sample configuration: the simplest one for two shards. Here is the code from bat files:

cd c:\mongodb-win32-x86_64-1.8.3-rc1\bin 
call mongod --shardsvr --dbpath /data/db/Shard--port 10000 
cd c:\mongodb-win32-x86_64-1.8.3-rc1\bin 
call mongod --shardsvr --dbpath /data/db/Shard2 --port 10001 
cd c:\mongodb-win32-x86_64-1.8.3-rc1\bin 
mongod --configsvr --dbpath /data/db/config --port 20000 
cd c:\mongodb-win32-x86_64-1.8.3-rc1\bin 
mongos --configdb 192.168.0.23:20000 
cd c:\mongodb-win32-x86_64-1.8.3-rc1\bin 
mongo 
use admin 
db.runCommand( { addshard : "192.168.0.23:10000" } ) 
db.runCommand( { addshard : "192.168.0.23:10001" } ) 
db.runCommand( { enablesharding : "Shard" } ) 
db.runCommand( { shardcollection : "Shard.Customers", key : 
{LocalIdentifier : 1} } ) 

When I try executing a simple inserting code to this DB, it executes but both shards are empty. Here is the inserting code:

public void SaveBatch(IEnumerable<object> entities) 
{ 
    MongoCollection.InsertBatch(typeof(object), entities, SafeMode.True); 
} 

Also this is the code executing on connection:

string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; 
mongoServer = mongoServer.Create(connectionSt开发者_如何学Goring); 
mongoDatabase = mongoServer.GetDatabase("Shard"); 
mongoCollection = mongoDatabase.GetCollection<Customer>("Customers"); 
mongoCollection.EnsureIndex( 
    IndexKeys.Ascending(new[] {"CampaignId", "LocalIdentifier", "ProjectIdentifier", "FirstName", "LastName"})); 

So I did not manage to make the shards work. Can you tell me what I am wrong at: configuring, connecting or inserting? And what is the right way to do it?


Seems to me you're sharding Shards.Customers, but inserting into Riverdale.Customers. Am I missing something?


The solution posted in the question works fine

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号