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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:09:06+00:00 2026-05-30T05:09:06+00:00

I have a collection containing data similiar to this: { dimension1:a, dimension2:b, dimension3:c, dimension4:d,

  • 0

I have a collection containing data similiar to this:

{
dimension1:a,
dimension2:b,
dimension3:c,
dimension4:d,
dimension5:e,
value: x
}

there is a finite number of values that a,b,c,d,e can have. Therefore it is possible to see two rows with identical dimensions and different stored values, like this:

{ dimension1:1, dimension2:1, dimension3:1, dimension4:1, dimension5:1, value: 12 }
{ dimension1:1, dimension2:1, dimension3:1, dimension4:1, dimension5:1, value: 34 }

I would like to aggregate objects with matching dimensions and replace them with one object with a sum of values.

I am aware of the fact that I can do it with mapReduce, but is there a way to do it simpler/faster or even assure that my insert statement would add to an existing value if there is one?

[edit]

I also see that db.collection.group() seems designed to do such a thing, but it can’t handle my size of data

  • 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-30T05:09:08+00:00Added an answer on May 30, 2026 at 5:09 am

    I think you want an Upsert With Modifier. This would satisfy your second approach, so that you insert a row if no matching row exists, or just add the value if a matching row does exist.

    So you example would be something like:

    db.mycollection.update( { dimension1: a, ... dimension5: e }, { $inc: { value: x } }, true); //the 'true' is the param that makes this update an upsert
    

    If you want to insert all the individual values then aggregate them later I would suggest you aggregated them to a separate collection (to avoid confusion). Probably the easiest way to do this would be with a map/reduce rather than a group, as you can simply set the output options of the map/reduce to merge its output into the aggregate collection with options like this: out : {reduce: "aggregatedcollection"}.

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

Sidebar

Related Questions

I have a collection containing a LOT of Data Transfer Objects that I need
I have Collection List<Car> . How to compare each item from this collection with
I have this problem: I have a collection of small files that are about
I have a data model something like this: # columns include collection_item_id, collection_id, item_id,
I have data database containing some rather large strings, each of which holds a
I have a map. On this map I want to show live data collected
Let's say we have a data structure like this: var sequences = new List<Tuple<int,
I have a data structure made of Jobs each containing a set of Tasks.
I have a csv data set containing a date field which my may or
I'm planning to have collection of items stored in a TCollection. Each item will

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.