Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:03:17+00:00 2026-05-30T17:03:17+00:00

For my needs, I have to do pre-splitting but my shard key is a

  • 0

For my needs, I have to do pre-splitting but my shard key is a compound key. both keys of my compound key (k1 and k2) are int and my desired chunk structure is something like this

chunk1 : k1 = minkey to 1, k2 = minkey to maxkey

chunk2 : k1 = 1 to 2, k2 = minkey to maxkey

chunk3 : k1 = 2 to 3, k2 = minkey to maxkey

chunk4 : k1 = 3 to 4, k2 = minkey to maxkey
…

So what I really want to do is split on the first key only and leave the second key to include all possible ranges but if run this

db.runCommand( { split : "db.mycollection" , middle : { k1: 1} } );

it will fail saying the full shard key is not provided so it makes me to call this

db.runCommand( { split : "db.mycollection" , middle : { k1: 1, k2:somenumber } } );

this command works but the resulted split is bad because it gives me chunks like below

chunk1 : k1 = minkey to 1, k2 = minkey to somenumber

chunk2 : k1 = 1 to maxkey , k2 = somenumber to maxkey

this is bad because if users insert something a document where k1<1 and k2>somenumber, there is no chunk in the system that covers it and the insert should fail.

How can I create such chunk boundaries with my compound key?

NOTE: One may ask why I have k2 if it is always minkey to maxkey. I have k2 like that to allow further splitting on k2 for same k1 in future if needed be ( and I am sure it will be needed on some of chunks)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:03:19+00:00Added an answer on May 30, 2026 at 5:03 pm

    This should do it :

    db.runCommand( { split : "db.mycollection" , middle : { k1: 1, k2:MaxKey } } );
    db.runCommand( { split : "db.mycollection" , middle : { k1: 2, k2:MaxKey } } );
    db.runCommand( { split : "db.mycollection" , middle : { k1: 3, k2:MaxKey } } );
    db.runCommand( { split : "db.mycollection" , middle : { k1: 4, k2:MaxKey } } );
    

    By the way, you can never create a situation where a certain range is not covered by chunks since all you’re doing is splitting existing ranges. Also note that k2 cannot be from MinKey to MaxKey technically. Your range for the first chunk is going to be {k1: MinKey, k2: MinKey} to {k1:1, k2: MaxKey}. The next one is going to be {k1: 1, k2: MaxKey} to {k1:2, k2: MaxKey} and so on

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET 3.5 site that needs to export data to a pre-formatted
I have a pre-requisite that I need to declare for a target that needs
I have pre populated database of around 25 MB, which needs to be copied
I have an ASP.NET 4.0 web application which needs to be pre-compiled into a
I have a couple of pre-existing applications which I need to run in one
I have a strong use case for pre-allocating all the memory I need upfront
I have application with needs to have access to some sensitive data(in this case
I have a Cake website and it needs to have two separate logins, each
I have created an application which needs to have a profile box tab which
We have a pojo that needs to have a list of integers. As an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.