Coder Social home page Coder Social logo

mongodb-erlang's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongodb-erlang's Issues

mongodb-erlang's modify function return error

Hi, Mr Christkv, When I use mongodb-erlang's modify function,I had a problem.Could give me some tips, thank you very much!

erlang code ---

test_modify() ->
Actions = fun() -> mongo:modify(c1, {x,{'$lt',100}}, {y,10}) end,
do(Actions).

do(Actions) ->
case test_connection() of
{ok, Conn} ->
{State, Reason} = mongo:do(safe, master, Conn, testdb, Actions),
case {State, Reason} of
{failure, Reason} ->
mongo:disconnect(Conn),
{failure, Reason};
{ok, Result} ->
mongo:disconnect(Conn),
{ok, Result}
end;
{error, Reason} ->
{error, Reason}
end.
end code -----

my collections is :

mongo shell ----

db.c1.find();
{ "_id" : ObjectId("503b252196d6a81fb4000005"), "x" : 5, "y" : 6 }
{ "_id" : ObjectId("503b26ef96d6a81fb4000006"), "x" : 10, "y" : 11 }
{ "_id" : ObjectId("503b26ef96d6a81fb4000007"), "x" : 12, "y" : 13 }
{ "_id" : ObjectId("503b26ef96d6a81fb4000008"), "x" : 14, "y" : 15 }
end mongo shell ---

When running : test_modify/0 , there catch a error:

error code ---
{failure,{write_failure,10158,
<<"multi update only works with $ operators">>}}
end error code ---

Support for mongo's `Infinity`

Loading documents that contains Infinity fails due to BSON parsers can't decode the float:

// insert in mongo shell
db.test.insert({"hello": Infinity})
# try to query back
:poolboy.transaction :mongodb, fn(conn) -> :mongo.find_one(conn, :test, %{}) end
** (exit) exited in: :gen_server.call(#PID<0.3001.0>, {:query, false, false, false, false, :test, 0, -1, %{}, []}, :infinity)
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: <<0, 0, 0, 0, 0, 0, 240, 127>>
            (bson) src/bson_binary.erl:87: :bson_binary.get_field/4
            (bson) src/bson_binary.erl:144: :bson_binary.get_field/2
            (bson) src/bson_binary.erl:54: :bson_binary.get_fields/2
            (bson) src/bson_binary.erl:40: :bson_binary.get_map/1
            (mongodb) src/core/mongo_protocol.erl:111: :mongo_protocol.get_docs/3
            (mongodb) src/core/mongo_protocol.erl:92: :mongo_protocol.get_reply/1
            (mongodb) src/connection/mc_worker_logic.erl:68: :mc_worker_logic.decode_responses/2
            (mongodb) src/connection/mc_worker.erl:102: :mc_worker.handle_info/2

There is a pull request for it in the bson-erlang repo put i'm posting it here for reference.

distinct query

Hi,

I can't figure out which api method to use to write a "distinct" query with both keys and selectors.

Any help please ?

BinData(4, binary) - how to achieve?

Hi,

currently I'm using the following erlang tuple to generate an "_id" with BinData(3, binary):

generate_objectid_subtype3() ->
    {bin, uuid, uuid:uuid4()}.

How can I achieve that MongoDB will get a BinData of Type 4?

maps support?

Does mongodb-erlang support the maps syntax ?

maps is easy for insert and match the query result

Example:

mongo:insert(Connection, Collection, #{name => <<"Tom">>, age => 22 }),
mongo:update(Connection, Collection, #{'$set' => #{age => 33 }}),
Data = mongo:find_one(Connection, Collection, #{age => 30}),
#{name := Name} = Data

Connection with login password

Hello, I'm trying to connect to remote mongo server 2.6.4 like this

mongo:connect([{database, list_to_binary(DB)}, {host, Host}, {port, Port}, {login, list_to_binary(U)}, {password, list_to_binary(P)}])

and getting this error

[error] CRASH REPORT Process <0.376.0> with 1 neighbours crashed with reason: bad argument in call to erlang:iolist_to_binary([{ok.......<<"my_login_here">>......in crypto:hash/2 line 223

Connection like this

mongo:connect([{database, list_to_binary(DB)}, {host, Host}, {port, Port}

works just fine in the same time.
Any ideas?

Authentication problem

While trying to connect to mongodb with login and password, i am getting <<"Can't pass authentification">>.
Login & Password are correct and working with other application.

mc_worker:start_link([{database, <<"database">>},{login, <<"admin">>},{password, <<"password">>},{host,"x.x.x.x"},{port,27017}]).

[error] CRASH REPORT Process <0.478.0> with 1 neighbours crashed with reason: <<"Can't pass authentification">> in mc_auth_logic:scram_sha_1_auth/4 line 34

how to use find api to regex data

I want use selector {field_name, '$regex', "/data/i"}
find data

mongod-2.6version is ok

mongod-3.0version is badValue '$regex' to a string

connect/6 example

Hi, could you please provide example how to use connect/6 with empty username and password
Why I need this?
I have not auth, but want to tune DB server IP and port.

Thanks in advance.

Give a way to query by id

mongo:find_one(my_collection, {<<"_id">>, <<82,29,123,102,44,196,167,32,184,0,0,1>>}). %% Does not work, nor does replacing with <<"ObjectId("my_id")">> or the base64 representation.

How do I query for the id?

Can I set mongod socket always active once?

case dict:size(UReqStor) of
    0 -> ok;
    _ -> inet:setopts(State#state.socket, [{active, once}]) %TODO why not always active true?
  end,

When I use poolboy, mc_worker can't recognize tcp closed bucause socket not set active once when mc_worker is idle

Add LICENSE

Could you please add licensing terms? I know this driver has long history starting from 10gen but anyway.

Support for MONGOHQ?

Hi

I have been using this plugin to connect to mongohq

While I can establish an initial connection to the databse it throws an error everytime i try to do a query such as find:

=ERROR REPORT==== 15-Jul-2013::12:34:45 ===
      Conn: GET /
    Reason: (MatchError) no match of right hand side value: {:failure, :unauthorized}
Stacktrace:
  lib/dynamodemoapp/models/task.ex:2: Tasks.find_all/2

The custom code above is just a wrapper to :mongo.find

It seems that there is an authorization error failure? and i can't work out why it is causing it as it uses the same connection parameters as if you are connecting to localhost?

any help or pointers will be useful

thanks!

ensure_index syntax

Does anyone know about ensure_syntax?

I tried

mongo:ensure_index(DBConn, conversations, {key, {page_id, 1}, unique, true, dropDups, true})

but not work at all

Undefined function error

It throws undefined function error

$ erl -pa ebin deps/*/ebin
Erlang R16B (erts-5.10.1) [source-05f1189] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.1  (abort with ^G)
1> application:start(bson).
ok
2> application:start(mongodb).
ok
3> mongo:connect({localhost, 27017}).
** exception error: undefined function mongo:connect/1

Why?

How to insert an ISODate to MongoDB

Hi,

currently I insert datetimes as ISO8601 timestamp string but I'd like to change that to the MongoDB Datatype ISODate.

How can I achieve this?

Thanks

Cannot connect to remote Mongo server

This driver seems very nice. I use it in my elixir project.
This is my code to connect to my remote mongo server. But it returns error.

iex> :mongo.connect("db_name", "account", "password", "safe", "master", [{"host", "example.com"}, {"port", 27017}])
** (EXIT from #PID<0.88.0>) {:errmsg, "auth failed", :code, 18}

(I've tried to connect by my local mongo client and it works.)
Is this right format of the :mongo.connect/6 command when use in elixir?
Please help me!

How to sort and limit a find query ?

I have been searching everywhere, I can't find for the life of me how to sort a find query and ordering it... has it been forget ?

Other less supported drivers does it, I do see why this one couldn't be able to...

Any clue would be greatly appreciated.

dynamically created atoms in soundrop/bson-erlang

Hi,
I'm trying to write an Erlang application that connects to MongoDB and I looked into using this client driver.

I notice that soundrop/bson-erlang (the rebar dependency) maps document field names to Erlang atoms using binary_to_atom. This is visible in the bson parser code (bson_binary:get_fields) and also mentioned in the blog post, http://blog.mongodb.org/post/7270427645/design-of-the-erlang-driver-for-mongodb .

I think it's very dangerous to use binary_to_atom like that, since atoms are not garbage collected and so document collections containing too many different field names can overrun memory in the Erlang node. I'd consider this a critical bug (in my application I can't control what's in documents and might even get malicious ones) so I can't use the driver like that. I'd urge a refactoring to not use atoms in this unsafe way, that the Erlang documentation advises against.

I thought about just modifying the driver and sending you a patch, but since it would be an API change, I decided I better ask your advice about it first. It's of course also possible that I'm missing something, in which case enlightenment is always appreciated. Please let me know your thoughts.

(Note: I tried emailing this but it bounced).

Thanks

--Paul

Instructions in Readme are outdated.

Subj.
First of all: installing into lib directory returned by code:lib_dir() does not work as per instructions. In reality you have to create two directories:
one for mongodb, one for bson, e.g.
/usr/lib64/erlang/lib/mongo-master
and
/usr/lib64/erlang/lib/bson-master
Then it'll work.
Second - I'm now reading through code, as module mongo doesn't have connect function. I guess I have to use mongo_connect module, but there is no mention of it in docs, so one has to dig into the code. Bless open-source, by the way :)

Newby: undefined function mongo:connect/1

I followed the README and got stuck at trying to connect to my local instance with no auth.

$  erl -pa mongodb/ebin mongodb/deps/bson/ebin
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9.1  (abort with ^G)
1>  application:start (bson).                  
ok
2>  application:start (mongodb).
ok
3> Database = <<"test">>.
<<"test">>
4> {ok, Connection} = mongo:connect (Database).
** exception error: undefined function mongo:connect/1

the compile went fine, without errors.

Any suggestions?

p.s. i read the issue from 2 years ago that the api may have changed, but I saw the README being updated today, so I assume it correct now...

Can't pass authentification

Версия монги 3.0.
Версия erlang 18.
Cypto запущено.
Подключение:

ok, Connection} = mongo:connect ([
    {database, <<"dbname">>},
    {login, <<"user">>},
    {password, <<"pass">>}
  ])

в итоге "Can't pass authentification".
В эксепшене:
"A: error, B: {badmatch,{false,#{<<99,111,100,101>>=>18,<<101,114,114,109,115,103>>=><<65,117,116,104,101,110,116,105,99,97,116,105,111,110,32,102,97,105,108,101,100,46>>}}}".
Либо с другой учёткой:
"A: error, B: undef"

=CRASH REPORT==== 18-Aug-2015::12:47:27 ===
crasher:
initial call: mc_worker:init/1
pid: <0.96.0>
registered_name: []
exception error: <<"Can't pass authentification">>
in function mc_auth_logic:scram_sha_1_auth/4 (src/core/mc_auth_logic.erl, line 42)
in call from mc_worker:init/1 (src/connection/mc_worker.erl, line 41)
ancestors: [<0.94.0>]
messages: []
links: [<0.94.0>,#Port<0.1592>]
dictionary: [{random_seed,{879,21160,14733}}]
trap_exit: false
status: running
heap_size: 987
stack_size: 27
reductions: 2920
neighbours:
neighbour: [{pid,<0.94.0>},
{registered_name,[]},
{initial_call,{erlang,apply,2}},
{current_function,{proc_lib,sync_wait,2}},
{ancestors,[]},
{messages,[]},
{links,[<0.26.0>,<0.96.0>]},
{dictionary,[]},
{trap_exit,false},
{status,waiting},
{heap_size,233},
{stack_size,29},
{reductions,498}]
** exception exit: <<"Can't pass authentification">>

С теми же данными из php подключаюсь без проблем. Куда копать?

Finish refactoring

  • made safe write confirmation and write in one transaction. ( comtihon:refactor )

How to "save" Connection pid between queries?

I am writing backend storage for Erl db abstraction lib kvs.
There is start fun in kvs, that establish connection with mongoDB. How I can store connection, to re-use for future queries?

I understand that result of connection is PID of connection process, but what is next?

How mongodb-erlang suggest that external apps will use it? any recommendation?

How to retrieve the actual value of an id?

I have tried the bson:utf8() method... but doesn't help.

Basically how do I turn the binary representation into a string-like representation?

<<83,22,19,109,142,79,136,52,52,0,0,1>> --> "5314e0d68e4f8823fb000001"

compiling error

When compiling the driver using the cmd 'erlc -o ebin -I include -I .. src/*.erl
', I get the error info:
src/mongo.erl:333: syntax error before: '.'
src/mongo.erl:32: function add_user/3 undefined
src/mongo.erl:330: spec for undefined function mongo:add_user/3

And then I fixed it with:

before
add_user (Permission, Username, Password) ->
User = case find_one (system.users, {user, Username}) of {} -> {user, Username}; {Doc} -> Doc end,
Rec = {readOnly, case Permission of read_only -> true; read_write -> false end, pwd, pw_hash (Username, Password)},
save (system.users, bson:merge (Rec, User)).

after
add_user (Permission, Username, Password) ->
User = case find_one ('system.users', {user, Username}) of {} -> {user, Username}; {Doc} -> Doc end,
Rec = {readOnly, case Permission of read_only -> true; read_write -> false end, pwd, pw_hash (Username, Password)},
save ('system.users', bson:merge (Rec, User)).

Connect to mongo with auth

Can someone give me an example of connect to a remote mongodb server with username and password? I tried several ways but didn't work.

Best Regards,

Can't connect to DB after integer exceeds 32 bits

Our server is using mongoerl in master branch. We found a bug which causes our server down about every month in mongoerl. The trace is as follows:

["web request failed",
{path,"l"},
{type,error},
{what,{badmatch,{-2146148680,
{reply,false,false,true,0,0,
[{setName,<<"rs0">>,ismaster,true,secondary,false,
hosts,
[<<"ip-10-121-13-170:27017">>,
<<"ip-10-121-12-150:27017">>,
<<"ip-10-121-12-108:27017">>],
primary,<<"ip-10-121-13-170:27017">>,me,
<<"ip-10-121-13-170:27017">>,
maxBsonObjectSize,16777216,
maxMessageSizeBytes,48000000,localTime,
{1371,74346,818000},
ok,1.0}]},
<<>>}}},

After looking into the source of mongodb-erlang, I think this is mainly because that after request_id was requested more than 2147483647 times(every time it will use ets:update_counter to increase by 1), it will be larger than 32 bit int, then this error will occur. We are using this in production environment so we need a urgent fix. I checked refactor branch, it seems not many documents on that new branch with new interfaces and so it's impossible for us to risk upgrading it to new. Could anyone please tell me what to do to avoid this problem, probably a quick fix for this in mongoerl?

Thanks very much

MongoDB 3.0 auth mechanism

Hi, is there any plan to support SCRAM-SHA-1 auth mechanism to work with MongoDB 3.0 ?

Best regards,

Morgan.

Change rebar.config

In file rebar.config change atom fail_on_warning to warnings_as_errors.
Atom fail_on_warning is deprecated

distinct command does not work

I'm trying to get all the distinct values of some collection, I can get the result by executing db.$cmd.findOne({distinct: collection_name, key: some_key}) from within the shell. However, when I do:

mongo:do(safe, master, DbConn, some_db,
  fun() ->
    mongo:command(
      {
        distinct, some_collection,
        key, some_key
      }
    )
  end
)

I always get a blank list. I'm working on Ubuntu 12.04 + MongoDb 2.2.1 + Erlang R15B02.

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.