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

  • Home
  • SEARCH
  • 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 8272221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:03:56+00:00 2026-06-08T07:03:56+00:00

I am working on a page hierarchy (mongodb document): { _id: 012, content: lorem

  • 0

I am working on a page hierarchy (mongodb document):

{
    _id: 012,
    content: "lorem ipsum whatever...",
    subpages: [123,234,345,456], // page ids
}

The page structure will actually be highly dynamic, so many updates will occur simultaneously with many reads. However, every change (like moving a subpage into another page) requires at least 2 update operations:

// move 123 into page 234
db.pages.update({"_id":012}, {$pull:{"subpages":123}});
db.pages.update({"_id":234}, {$push:{"subpages":123}});

// delete page 345
db.pages.update({"_id":012}, {$pull:{"subpages":345}});
db.pages.remove({"_id":345});

Is there a way to perform (or design the model to enable performing) operations like moving a page or deleting a page atomically (to prevent the state of the hierarchy going bad)?

Notes

One possibility I’m looking at right now is manually locking the documents by adding a “lockedBy” field to every page, which will contain a transaction ID. But I don’t like the idea of continuously polling if I want a second locking operation to block until the first locking operation completes (see https://jira.mongodb.org/browse/SERVER-2244). Also, since locking is managed by the application, if the application (or one instance of it) goes down for whatever reason during a locking operation, the documents need to be unlocked somehow, without affecting other transactions.

I’ve also looked at http://www.mongodb.org/display/DOCS/Trees+in+MongoDB and it seems that none of the examples (except for the single document one) solves this problem. However, I would like to avoid putting the entire hierarchy into a single document, because of the 16MB document size constraint and the difficulty of moving pages around (basically I need to upsert the entire document for every change).

Updates

We hope to support up to 10000 subpages for a page. The IDs for pages are at least 6 characters long. With that in mind, we moved from mySQL because we need to keep track of the order of the sub-pages. Since mySQL doesn’t have array structures, the only way to do that is to use a position column. When pages are moved around frequently, it is expensive to calculate average positions and re-index when the position value becomes too long. Also, if we wanted to put a comma separated list of ids into a column, we would have to use a TEXT column (read from disk) rather than a VARCHAR (which has a limit of 65536 chars) in order to support 10000 sub-pages.

  • 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-06-08T07:03:57+00:00Added an answer on June 8, 2026 at 7:03 am

    There are no transactions. There are atomic operations but they only operate on one document at a time. I’d say, your only choice for a reliable update is to put the whole hierarchy into one document. I wouldn’t worry too much about running over document limit: 16MB is a LOT of integers.

    Also I think, this is an example where a “regular” relational transactional database is much more useful.

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

Sidebar

Related Questions

I'm working on an ASP.NET page, using VB.NET and I have this hierarchy: Page
Here is my working page . I attached buttons to white bishop and you
I'm working with page template in WordPress (don't matter). I'll try insert a picture
What I have here is a PHP page working with the Facebook API. What
Working on a page with multiple sections. at the very top there is a
I am working on a page in ASP.NET/C# where the user's information is saved
I'm working on a page that has three divs next to each other, each
so im working on a page to learn Yii. this is it: http://devcave.freeiz.com/ What
I am working on a page cache replacement policy, I read many existing algorithms
I'm working on a page where I need to associate a list of objects

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.