与春季蒙哥分片 [英] Sharding with spring mongo

查看:85
本文介绍了与春季蒙哥分片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mongoDB通过Spring Web应用程序存储和查询近5000万条记录(无固定模式的大型Json文件).简单的基于K-V对的查找查询需要几秒钟的时间.我正在寻找使搜索时间降至< 1秒

I'm using mongoDB for storing and querying close to 50 mn records (Large Json files with no fixed schema), through a spring web application. Simple K-V pair based find queries run into a few seconds. I'm looking at ways to bring search time down to < 1s.

由于存储文件的性质,索引对我不起作用.我当时正在寻找替代品,并遇到了分片.但是,我找不到很好的教程来解释如何为现有的spring-mongo应用程序设置分片.

Indexing doesn't work for me because of the nature of the files stored. I was looking at alternatives and came across sharding. However, I found no good tutorial explaining how to set up sharding for my existing spring-mongo application.

有人可以为我指出一个很好的解释吗? 也欢迎其他任何优化搜索时间的建议!

Can someone please point me towards a good explanation for the same? Also any other suggestions for optimizing search time would be welcome!

编辑

在评论之后,我将现有的Mongo数据库转换为具有1个配置服务器,1个查询服务器和2个分片的分片数据库.以前,我的(spring-boot)application.properties文件看起来像这样:

Following the comment, I converted my existing Mongo database into a sharded one with 1 config server, 1 query server and 2 shards. Previously my (spring-boot) application.properties file looked like this :

...
spring.data.mongodb.database=pam
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.repositories.enabled=true
spring.data.mongodb.uri=mongodb://localhost:27017/pam
...

我现在如何修改它以适应具有相同名称的分片数据库?

How do I modify it now to adapt to the sharded database, with the same name?

推荐答案

如果您仔细阅读了文档 https://docs.mongodb.com/manual/sharding/,您将同意分片的事实对于系统的其余部分是透明的,并且应该是透明的.最初,您的系统可以是单个数据库,然后是完整的分片,

If you read carefully docs https://docs.mongodb.com/manual/sharding/ you would agree that fact of sharding is and should be transparent for the rest of the system. That is initially your system can be just single database, and then full shard with

  • mongos路由器
  • 配置服务器
  • 碎片(即副本)
  • mongos Router
  • Config Server
  • Shards (that are replicas)

即分片是部署问题,而不是设计问题. MongoDB界面保持不变.

i.e. sharding is deployment question, not a design. MongoDB interface stays the same.

这篇关于与春季蒙哥分片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆