Giter Site home page Giter Site logo

ensure_index syntax about mongodb-erlang HOT 15 CLOSED

comtihon avatar comtihon commented on August 28, 2024
ensure_index syntax

from mongodb-erlang.

Comments (15)

comtihon avatar comtihon commented on August 28, 2024

mongo:ensure_index(Worker, Collection, {key, {tag, 1}, name, <<"tag_index">>})
this works, name parameter is optional.
The dropDups option is no longer available since mongo 3. What version of mongo do you try?

from mongodb-erlang.

phongmh307 avatar phongmh307 commented on August 28, 2024

i'm using mongo 2.6.5

It turns out when I put my code into console, it works and return ok, but if I put it in my application, even at the end, the app crashed

from mongodb-erlang.

comtihon avatar comtihon commented on August 28, 2024

Could you post a crash log here?

from mongodb-erlang.

phongmh307 avatar phongmh307 commented on August 28, 2024

This is crash log. Thank you

=ERROR REPORT==== 16-Apr-2015::14:50:25 ===
** Generic server <0.104.0> terminating
** Last message in was {ensure_index,conversations,{key,{page_id,1}}}
** When Server state == {state,#Port<0.3347>,49181,<<>>,
                               {conn_state,unsafe,master,pancake_development}}
** Reason for termination ==
** {function_clause,
       [{mongo_protocol,'-put_message/3-lbc$^0/2-0-',
            [{name,<<"i_page_id_1">>,unique,false,dropDups,false,key,
                 {page_id,1},
                 ns,<<"pancake_development.conversations">>},
             <<>>],
            [{file,"src/core/mongo_protocol.erl"},{line,49}]},
        {mongo_protocol,put_message,3,
            [{file,"src/core/mongo_protocol.erl"},{line,49}]},
        {mc_worker_logic,'-encode_requests/2-fun-0-',3,
            [{file,"src/connection/mc_worker_logic.erl"},{line,22}]},
        {lists,foldl,3,[{file,"lists.erl"},{line,1261}]},
        {mc_worker_logic,make_request,3,
            [{file,"src/connection/mc_worker_logic.erl"},{line,71}]},
        {mc_worker,handle_call,3,
            [{file,"src/connection/mc_worker.erl"},{line,44}]},
        {gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,607}]},
        {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]}]}

=ERROR REPORT==== 16-Apr-2015::14:50:25 ===
** Generic server <0.98.0> terminating
** Last message in was {'EXIT',<0.48.0>,
                        {function_clause,
                         [{mongo_protocol,'-put_message/3-lbc$^0/2-0-',
                           [{name,<<"i_page_id_1">>,unique,false,dropDups,
                             false,key,
                             {page_id,1},
                             ns,<<"pancake_development.conversations">>},
                            <<>>],
                           [{file,"src/core/mongo_protocol.erl"},{line,49}]},
                          {mongo_protocol,put_message,3,
                           [{file,"src/core/mongo_protocol.erl"},{line,49}]},
                          {mc_worker_logic,'-encode_requests/2-fun-0-',3,
                           [{file,"src/connection/mc_worker_logic.erl"},
                            {line,22}]},
                          {lists,foldl,3,[{file,"lists.erl"},{line,1261}]},
                          {mc_worker_logic,make_request,3,
                           [{file,"src/connection/mc_worker_logic.erl"},
                            {line,71}]},
                          {mc_worker,handle_call,3,
                           [{file,"src/connection/mc_worker.erl"},{line,44}]},
                          {gen_server,try_handle_call,4,
                           [{file,"gen_server.erl"},{line,607}]},
                          {gen_server,handle_msg,5,
                           [{file,"gen_server.erl"},{line,639}]}]}}
** When Server state == {state,#Port<0.2447>,45084,<<>>,
                               {conn_state,unsafe,master,pancake_development}}
** Reason for termination ==
** {function_clause,
       [{mongo_protocol,'-put_message/3-lbc$^0/2-0-',
            [{name,<<"i_page_id_1">>,unique,false,dropDups,false,key,
                 {page_id,1},
                 ns,<<"pancake_development.conversations">>},
             <<>>],
            [{file,"src/core/mongo_protocol.erl"},{line,49}]},
        {mongo_protocol,put_message,3,
            [{file,"src/core/mongo_protocol.erl"},{line,49}]},
        {mc_worker_logic,'-encode_requests/2-fun-0-',3,
            [{file,"src/connection/mc_worker_logic.erl"},{line,22}]},
        {lists,foldl,3,[{file,"lists.erl"},{line,1261}]},
        {mc_worker_logic,make_request,3,
            [{file,"src/connection/mc_worker_logic.erl"},{line,71}]},
        {mc_worker,handle_call,3,
            [{file,"src/connection/mc_worker.erl"},{line,44}]},
        {gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,607}]},
        {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]}]}
[*] Waiting for messages. To exit, press Ctrl+C

from mongodb-erlang.

comtihon avatar comtihon commented on August 28, 2024

I investigate this issue.
When using mongodb-erlang name parameter is a must. That is why mongo:ensure_index(DBConn, <<"test">>, {key, {key, 1}}) won't work.
In shell, when you add index with db.test.createIndex({"test" : 1}, []) - index name will be assigned from key parameter (name = test).
So, for your situation - just add name to the document:
mongo:ensure_index(DBConn, conversations, {key, {page_id, 1}, unique, true, dropDups, true, name, <<"page_id">>}).

from mongodb-erlang.

comtihon avatar comtihon commented on August 28, 2024

Please post me your call to mongo, which leads to the crash.

from mongodb-erlang.

phongmh307 avatar phongmh307 commented on August 28, 2024

This is my call to mongo:
mongo:ensure_index(DBConn, conversations, {key, {page_id, 1}, unique, true, dropDups, true})
I called it immediately below mongo connect.

By the way, please apologize for the delay in response.

from mongodb-erlang.

phongmh307 avatar phongmh307 commented on August 28, 2024

I tried your method, didn't work.

Do you have any idea about this issue?

from mongodb-erlang.

comtihon avatar comtihon commented on August 28, 2024

Please - post you call to mongo:ensure_index

from mongodb-erlang.

phongmh307 avatar phongmh307 commented on August 28, 2024

this is my mongo:ensure_index call:

mongo:ensure_index(DBConn, conversations, {key, {page_id, 1}, unique, true, dropDups, true, name, <<"page_id_1">>})

and crash log

=ERROR REPORT==== 9-Jun-2015::18:29:09 ===
** Generic server <0.94.0> terminating
** Last message in was {ensure_index,conversations,
                           {key,
                               {page_id,1},
                               unique,true,dropDups,true,name,
                               <<"page_id_1">>}}
** When Server state == {state,#Port<0.2735>,45084,<<>>,
                               {conn_state,unsafe,master,cake_development}}
** Reason for termination ==
** {function_clause,
       [{mongo_protocol,'-put_message/3-lbc$^0/2-0-',
            [{name,<<"page_id_1">>,unique,true,dropDups,true,key,
                 {page_id,1},
                 ns,<<"cake_development.conversations">>},
             <<>>],
            [{file,"src/core/mongo_protocol.erl"},{line,49}]},
        {mongo_protocol,put_message,3,
            [{file,"src/core/mongo_protocol.erl"},{line,49}]},
        {mc_worker_logic,'-encode_requests/2-fun-0-',3,
            [{file,"src/connection/mc_worker_logic.erl"},{line,22}]},
        {lists,foldl,3,[{file,"lists.erl"},{line,1261}]},
        {mc_worker_logic,make_request,3,
            [{file,"src/connection/mc_worker_logic.erl"},{line,71}]},
        {mc_worker,handle_call,3,
            [{file,"src/connection/mc_worker.erl"},{line,44}]},
        {gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,607}]},
        {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]}]}

from mongodb-erlang.

comtihon avatar comtihon commented on August 28, 2024

May be you should try to set name as key? <<"page_id">> instead <<"page_id_1">>

from mongodb-erlang.

phongmh307 avatar phongmh307 commented on August 28, 2024

I tried both cases and they both crashed. Does this issue relate to my mongo version?

Thanks

from mongodb-erlang.

comtihon avatar comtihon commented on August 28, 2024

I do not test ensure index on 2.6.5, so I can't answer. It will be good - if you test your code on newer version of mongo.

from mongodb-erlang.

phongmh307 avatar phongmh307 commented on August 28, 2024

I will upgrade mongo and report back to you asap!

On Jun 9, 2015, at 6:58 PM, Valery [email protected] wrote:

I do not test ensure index on 2.6.5, so I can't answer. It will be good - if you test your code on newer version of mongo.


Reply to this email directly or view it on GitHub #64 (comment).

from mongodb-erlang.

comtihon avatar comtihon commented on August 28, 2024

Thanks!

from mongodb-erlang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.