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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:32:25+00:00 2026-06-07T02:32:25+00:00

Hi im newbie into MongoDB and im needing to translate this sql query to

  • 0

Hi im newbie into MongoDB and im needing to translate this sql query to mongodb using two techniques first in MapReduce method and other Aggregation method. Someone may help?

select
    sum(l_extendedprice*l_discount) as revenue
from 
    lineitem
where 
    l_shipdate >= date '1994-01-01'
    and l_shipdate < date '1994-01-01' + interval '1' year
    and l_discount between 0.06 - 0.01 and 0.06 + 0.01
    and l_quantity < 24;
  • 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-07T02:32:27+00:00Added an answer on June 7, 2026 at 2:32 am

    http://www.mongodb.org/display/DOCS/MapReduce

    For your sample, using map/reduce

    var m = function () { emit(1, {this.l_extendedprice * this.l_discount})};
    
    var r = function (k, vals) {
        var sum = 0;
        for (var i = 0; i < vals.length; i++) {
           sum += vals[i];
        }
        return sum;
    }
    
    var res = db.stuff.mapReduce(m, r,  {
                                out:"stuff_aggr",
                                query: { 
                                    "l_shipdate": {$gte:  ISODate("1994-01-01T00:00:00.000Z")}, 
                                    "l_shipdate": {$lte:  ISODate("1995-01-01T00:00:00.000Z")},
                                    "l_discount": {$gte: 0.05}, 
                                    "l_discount": {$lte: 0.07}, 
                                    "l_quantity": {$lt: 24}
                                }
    });
    

    Aggregation is still a beta feature. MapReduce is still the better option. Am assuming you wanted to see if a complex where clause can be handled easily… Its not that different from SQL as long as you are restricting yourself to one collection/table.

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

Sidebar

Related Questions

Newbie to ruby this is my first project I am using the FasterCSV Gem
I'm pretty much a newbie and I need to dig into this matter to
I am newbie to db programming and need help with optimizing this query: Given
I am a newbie into Windows Service I have installed my Windows service using
MongoDB newbie issue: I have a lot of HTTP logs stored into a collection
I'm a newbie using Ninject and I can't figure out how to inject into
I am a Symfony2 newbie running into problems with edit-forms and doctrine. I seem
I am quite a newbie with OSGi and struggeling with including bundles into my
Im a .net newbie, I ran into a problem where the listbox is taking
Newbie in testing. I generated a test case using Selenium, and then exported it

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.