使用 C# 驱动程序在 MongoDB 中进行分片

发布于 2024-11-30 12:27:38 字数 1519 浏览 2 评论 0原文

我尝试尝试分片并制作一个示例配置:两个分片的最简单配置。这是bat文件中的代码:

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} } ) 

当我尝试执行一个简单的插入代码到该数据库时,它会执行 但两个碎片都是空的。这是插入代码:

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

这也是在连接上执行的代码:

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

所以我没有设法使分片工作。你能告诉我我是什么吗 错误之处:配置、连接或插入?什么是正确的 怎么办?

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("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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

写下不归期 2024-12-07 12:27:38

在我看来,您正在对 Shards.Customers 进行分片,但插入到 Riverdale.Customers 中。我错过了什么吗?

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

蓝眸 2024-12-07 12:27:38

问题中发布的解决方案效果很好

The solution posted in the question works fine

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文