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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:18:18+00:00 2026-06-10T20:18:18+00:00

Ok, MongoDB experts, please take a look at my collection: [{ _id : item_0,

  • 0

Ok, MongoDB experts, please take a look at my collection:

[{
  "_id" : "item_0",
  "Name" : "Item 0",
  "Description" : "Some description for this item...",
  "Properties" : {
    "a" : 5.0,
    "b" : 0.0,
    "c" : 6.0,
    "d" : 6.0,
    "e" : 2.0,
    "f" : 0.0,
    "g" : 9.0,
    "h" : 3.0,
    "i" : 4.0,
    "j" : 5.0
  }
},
{ // 5.000-10.000 more items... }
]

I am using this aggregate to multiply a set of selected properties (in this case a, b, c and d), to then sort them by their product:

{
    "aggregate": "item",
    "pipeline": [
        {
            "$project": {
                "_id": 1,
                "Name": 1,
                "s": {
                    "$multiply": [
                        "$Properties.a",
                        "$Properties.b",
                        "$Properties.c",
                        "$Properties.d"
                    ]
                }
            }
        },
        {
            "$sort": {
                "s": -1
            }
        },
        {
            "$limit": 100
        }
    ]
}

Now this works fine and all, but when the number of items and properties increase the time to execute the aggregate will be increased a lot!

Is there any better way (more efficient) to achieve something like this? The search for the highest product (multiple of a set of properties) must be snappy. If there is a way to index this, with all different combinations of properties and have them cached or something? It’s OK that the indexing takes a while, as long as the querying is fast!

Thanks for any help in this matter, I appreciate it a lot!

  • 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-10T20:18:19+00:00Added an answer on June 10, 2026 at 8:18 pm

    Given your requirement for faster searching and efficiency, I think a better approach would be to use Map/Reduce with an output collection (at least until such time as the Aggregation Framework supports using a collection for output).

    There are several advantages to using an output collection for your use case.

    In particular:

    • you can have flexible indexing and sorting
    • the results do not have to be calculated in real-time for every query
    • you are not limited by the 16Mb BSON document size for inline results

    You can use the merge output option for Map/Reduce to update calculations in your output collection (essentially, this would be your cache).

    Depending on how often your various properties are updated, I would investigate an incremental approach based on a “last updated” timestamp or some other criteria that allows you to determine when values need to be recalculated. This would allow you to keep the batch sizes more manageable as your collection grows.

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

Sidebar

Related Questions

I'm using MongoDB to hold a collection of documents. Each document has an _id
Lets take a look at the following code: mongodb.js var mongo = require('mongodb') ,
This question is for all NoSQL and specially mongoDB experts out there. I started
In MongoDB I have a query which looks like this to find out for
Is MongoDB _id unique by default, or do I have to set it to
Is it possible to change the ObjectId field name from '_id' to 'id', or
MongoDB's shell extends SpiderMonkey. Is there a way to hook into some of SpiderMonkey's
MongoDB does provide a compact command to free deleted space on a single collection,
Need some expert suggestions on using '$in' while performing 'update' in mongodb collections. Here
MongoDB's db.printShardingStatus command, when run from a mongos process, prints some json corresponding to

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.