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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:43:08+00:00 2026-05-23T09:43:08+00:00

I have a background working with relational databases but recently started to dabble in

  • 0

I have a background working with relational databases but recently started to dabble in CouchDB and was surprised by how some non-relational operations, which would be simple in SQL, were not first-class functions in CouchDB.

I would appreciate you taking a moment to map each SQL statement below to its MapReduce equivalent.

SELECT COUNT(*) FROM products WHERE price < 20.00;
SELECT category, SUM(price) FROM products GROUP BY category;
UPDATE products SET price = 19.99 WHERE price = 20.00;
DELETE FROM products WHERE expires_at <= NOW();
  • 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-23T09:43:09+00:00Added an answer on May 23, 2026 at 9:43 am

    The SELECT commands are pretty easy. Bulk writes are a bit more complicated. Generally, you’ll use some view to retrieve the documents that need to be changed, then you’ll use the _bulk_docs API to send all the changes at once.

    Also, consult the documentation regarding views for details for how to issue queries. This includes ordering, grouping, etc.


    SELECT COUNT(*) FROM products WHERE price < 20.00;

    Map

    function (doc) {
      if (doc.price < 20) {
        emit(doc.price);
      }
    }
    

    Reduce

    _count
    

    If you need this to work with an arbitrary amount, not just 20, then you’ll need to emit the price in all cases, and use startkey and endkey to narrow down your resultset.


    SELECT category, SUM(price) FROM products GROUP BY category;

    Map

    function (doc) {
      emit(doc.category, doc.price);
    }
    

    Reduce

    _sum
    

    This map function essentially uses the category as the key, with the price as the value in your key/value pair. The reduce function will add up the prices for each different key.


    UPDATE products SET price = 19.99 WHERE price = 20.00;

    Map

    function (doc) {
      if (doc.price == 20) {
        emit(doc.price);
      }
    }
    

    Once your application pulls down the contents of this view, you’ll perform all the manipulations in your application code, then send back the results into the database via the _bulk_docs API.


    DELETE FROM products WHERE expires_at <= NOW();

    Map

    function (doc) {
      emit(doc.expires_at);
    }
    

    Depending on how your store your date-time values, you may need to adjust the map function as well as your query to the view. Using a timestamp (JS uses milliseconds instead of seconds) is probably the fastest way to accomplish this. Once you’ve set up your query, you’ll add a new field to each of these documents. _deleted: true. Once you send this list back into the database (again with _bulk_docs) all the specified documents will be deleted.

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

Sidebar

Related Questions

I have background service which access my SQL Server database. My background service working
I have C# background and been working with C# for so many years.. Recently,
I've recently started working with multi-threaded Winform applications and have run up against a
Background: We have an offshore group working up a Silverlight 2 prototype for us.
background:Me and my coworkers are working on asp.net mvc project ... we have a
First a bit of background. I have been working on the MS platform for
Background Currently, I am working on a Rails application. I have different products that
I have background music for some songs available in both .MID and .KAR formats,
I have a background worker which can be cancelled. The normal flows interrupt itself
Background I'm working on a an educational JavaScript application/site (SPA) that will eventually have

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.