Sharding and C# driver

111 views
Skip to first unread message

YuriyHohan

unread,
Aug 22, 2011, 2:26:41 AM8/22/11
to mongodb-csharp
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(connectionString);
mongoDatabase = mongoServer .GetDatabase("Riverdale");
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?

Robert Stam

unread,
Aug 22, 2011, 10:35:16 AM8/22/11
to mongodb-csharp
What is the value of the ConnectionString from your config file?

Did any of the mongo shell commands return an error?

Does the C# code throw any exceptions?

How did you test that the shards were empty?

YuriyHohan

unread,
Aug 22, 2011, 11:05:09 AM8/22/11
to mongodb-csharp
Robert, thank you for your answer. The problem was created by my other
code
Reply all
Reply to author
Forward
0 new messages