问题
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.
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!
EDIT
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?
回答1:
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
Router- Config Server
- Shards (that are replicas)
i.e. sharding is deployment question, not a design. MongoDB interface stays the same.
来源:https://stackoverflow.com/questions/35497070/sharding-with-spring-mongo