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 9229905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:41:19+00:00 2026-06-18T05:41:19+00:00

I’m using MongoDB in my project for statistical and data analysis things. My goal

  • 0

I’m using MongoDB in my project for statistical and data analysis things. My goal is design data to have best performance and scaleability.

Let’s assume I have several shops and a list of unique products per shop. And I need to query some data about the products, calculate some basic statistic (only by curtain shop).

Which way is better from the performance point of view: to have a Shop document and a list of products inside and then make querying only per this document.

Or better will be having separate collection with all products per all shops in it and then build queries for that collection?


Maybe the question itself: does mongodb could query through the body of one document with such efficient manner like through many documents.


UPD 1:
For now let’s assuming that products itself is quite small (Id, Price, Name, Count) and the amount of it is limited. (So I know for sure that it won’t be more than 1000 products per shop)

UPD2
Also lets assuming that I don’t want to read that database for the view purposes, just for statistics. (How much sold, which is most interesting, what groups and so on)

  • 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-18T05:41:21+00:00Added an answer on June 18, 2026 at 5:41 am

    As with all these question one of the main deciding factors is data size and growth.

    Will your data per shop exceed 16 meg? Judging by how many items a shop can have and how much data can be attributed to just a single item I would yes, very quickly.

    What I mean is imagine how many fields you have for a product:

    • Product id
    • Description
    • Price
    • Options
    • Currency
    • blurb
    • SKU
    • Barcode (or whatever)

    Some of these fields will be quite big, For example, the description of the product could be massive.

    However if on the off chance this is a very simple application and you are looking at a product that can be be fully contained in a single data row and shops which will never have more than 5-8,000 items then you could do better with subdocuments of the sort:

    {
        _id: ObjectId(),
        shop_name: 'toys r us',
        items: [
            { p_id: ObjectId(), price: '1000000', currency: 'GBP', description: 'fkf' }
        ]
    }
    

    Subdocuments do not come without their price though. Imagine you have a document that only has one subdocument, in 10 days has 100 and in 20, 1000.

    The fragmentation caused by the consistently growing documents could be quite significant. This lowers your performance for one. Not only will your performance become a problem but also fixing fragmentation is not a nice job and then later solving it in the applications logic is even harder.

    To understand more about how MongoDB actually works inside you can view this presentation: http://www.10gen.com/presentations/storage-engine-internals

    As for querying on a subdocument, it does require a little extra work on MongoDBs end but it is still quite cheap (cheaper than multiple round trips) providing you set it up right.

    Personally based on the information I have given above I would go for two collections but I don’t know the true extent of your scenario…

    Edit

    UPD 1: For now let’s assuming that products itself is quite small (Id, Price, Name, Count) and the amount of it is limited. (So I know for sure that it won’t be more than 1000 products per shop)

    Okay so your documents are small, probably a couple of bytes each. In this case you might be able to use subdocuments here with power of 2 sizes allocation to remedy some of that fragmentation: http://docs.mongodb.org/manual/reference/command/collMod/#usePowerOf2Sizes

    This could create a performant operation, still 1 to 1000 subdocuments can cause fragmentation however those fragments should be filled by smaller “new” shop documents when they come into existence.

    UPD2 Also lets assuming that I don’t want to read that database for the view purposes, just for statistics. (How much solds, which is most interesting, what groups and so on)

    So per shop, using subdocuments, you could easily get the totals of how much sold per shop like:

    db.shops.aggregate([
        // Match shop id 1
        {$match: {_id: 1}},
    
        // unwind the products for that shop
        {$unwind: '$products'},
    
        // Group back up by shop id and total amount sold
        {$group: {_id: '$_id', total_sold: {$sum: '$products.sold'}}}
    ])
    

    Using the new aggregation framework (since version 2.1): http://docs.mongodb.org/manual/applications/aggregation/

    So subdocuments can be just as easy as two separate collections to query on as well.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am using jsonparser to parse data and images obtained from json response. When
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.