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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:57:01+00:00 2026-06-05T13:57:01+00:00

I use mongodb-erlang driver for mongo db access in erlang. Some of my command

  • 0

I use mongodb-erlang driver for mongo db access in erlang. Some of my command execution:

34> {ok, Conn} = mongo:connect({localhost, 27017}).                                                          
{ok,{connection,{"localhost",27017},
                <0.89.0>,false,infinity}}

35> {ok, Data} = mongo:do(safe, master, Conn, homeweb, fun() -> mongo:find_one(user, {apartmentId, 1}) end).
{ok,{{'_id',{<<79,180,252,18,220,119,245,66,215,79,71,61>>},
            apartmentId,1.0,email,<<"e@mail.com">>,password,
            <<"efe6398127928f1b2e9ef3207fb82663">>}}}

Data is a tuple.

For example in php array is returned from find request and I can get id with code like this: $id = $result['_id'];.

The question is: how to access to fetched from db data in Erlang?

  • 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-05T13:57:03+00:00Added an answer on June 5, 2026 at 1:57 pm

    By pattern matching. In this case, “Data” holds the result, so you might do something like:

    1> {{'_id', {Id}, apartmentId, ApartmentId, email, Email, password, Password}} = Data.
    {{'_id',{<<79,180,252,18,220,119,245,66,215,79,71,61>>},
            apartmentId,1.0,email,<<"e@mail.com">>,password,
            <<"efe6398127928f1b2e9ef3207fb82663">>}}
    

    The words that start with an upper case will hold the values, so for example, you can print them:

    2> ApartmentId.
    1.0
    3> Email.
    <<"e@mail.com">>
    4> Password.
    <<"efe6398127928f1b2e9ef3207fb82663">>
    5> Id.
    <<79,180,252,18,220,119,245,66,215,79,71,61>>
    

    EDIT: You are actually doing pattern matching when you run your query. Notice the {ok, Data} = on the left side of the = operator. This is effectively matching that the result is a tuple in the form {ok, Data} and since Data is unbound up to that point, it is assigned to the query result.

    EDIT2: Since Data in this case is a bson(), you can refer to the erlang bson module (used as a dependency of the mongodb erlang driver): http://api.mongodb.org/erlang/bson/. There are specific functions you can use in this case, like bson:lookup/2 and bson:fields/1, passing as a parameter the bson() document (the result from mongodb:find_one/2)

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

Sidebar

Related Questions

I write some example on erlang and mongodb. As driver for mongodb I use
I have some problem with this mongoid. It's my first time to use mongoDB,
In C# it is possible to use the MongoDB driver to define a custom
I'm trying to use MongoDB's Java driver to make two updates ($set and $push)
I want to use mongodb for a project. OK yes, i able to connect
We use MongoDB to collect logs on pageviews. $collection_name = logs..date('Y')...date('m')...date('d'); $collection = $this->Mongo->$collection_name;
We decided to use mongodb for some web application (instead of mysql) but want
I want to try to use MongoDB to access large millions of rows of
I am trying to use MongoDB, C# and NoRM to work on some sample
I'm trying to use MongoDB to cache some data for me, but I can't

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.