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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:29:04+00:00 2026-05-24T05:29:04+00:00

I need some help with translating the following CouchDB views from javascript to erlang.

  • 0

I need some help with translating the following CouchDB views from javascript to erlang. I need them in erlang, because in javascript the view uses all of the available stack memory and crashes couchjs (see this bugreport https://issues.apache.org/jira/browse/COUCHDB-893).

The current map functions I have in javascript are:

sync/transaction_keys

function(doc) {
  if(doc.doc_type == "Device") {
      for(key in doc.transactions)
          emit(key, null);
  }
}

and sync/transcation

function(doc) {
  if(doc.doc_type == "Device") {
      for(key in doc.transactions) {
          t = doc.transactions[key];
          t.device = doc.device;
          emit(key, t);
     }
  }
}

An example document would be:

{
   "_id": "fcef7b5c-cbe6-31af-8363-2b446a7e4cf2",
   "_rev": "3-c90abd075404a75744fd3e5e4f04ebad",
   "device": "fcef7b5c-cbe6-31af-8363-2b446a7e4cf2",
   "doc_type": "Device",
   "transactions": {
       "79fe8630-c0c0-30c6-9913-79b2f93e3e6e": {
           "timestamp": 1309489169533,
           "version": 10008,
           "some_more_data" : "more_data"
       }
       "e4678930-c465-76a6-8821-75a3e888765a": {
           "timestamp": 1309489169533,
           "version": 10008,
           "some_more_data" : "more_data"
       }
   }
}

Basically sync/transaction_keys emits all keys of the transaction dictionary and sync/transaction does emit all entries in the transaction dictionary.

Unfortunately I never used Erlang before and I need to rewrite that code pretty soon, so any help is very welcomed.

Thanks in advance.

  • 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-24T05:29:06+00:00Added an answer on May 24, 2026 at 5:29 am

    I just did your second one (the more complicated one). The first can easily be extrapolated from there:

    fun({Doc}) ->
            %% Helper function to get a toplevel value from this doc.
            F = fun(B) -> proplists:get_value(B, Doc) end,
            %% switch on doc type
            case F(<<"doc_type">>) of
                <<"Device">> ->
                    %% Grab the transactions from this document
                    {Txns} = F(<<"transactions">>),
                    lists:foreach(fun({K,V}) ->
                                          %% Emit the key and the value as
                                          %% the transaction + the device
                                          %% id
                                          {T} = proplists:get_value(K, Txns),
                                          Emit(K, {[{<<"device">>, F(<<"device">>)} | T]})
                                  end,
                                 Txns);
                _ -> false %% Not a device -- ignoring this document
            end
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I need help with translating some code from VB to C#. Public Function ToBase36(ByVal
I need some help translating the following shell scripts calls to PHP curl -3
Need some help with extracting 2 pieces of information from the following string: viewed
I need some help from the shell-script gurus out there. I have a .txt
I need some help to be able to handle the following logic. The program
Need some help designing a bash script for grepping IP addresses from auth.log and
Need some help. This javascript code should set the target of the form and
Need some help about with Memcache. I have created a class and want to
Need some help, please. I have a line of horizontal thumbnails loaded as ONE

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.