checkiz / elixir-mongo

MongoDB driver for Elixir
MIT License
101 stars 31 forks source link

Please add useful documentation #30

Open tastywheat opened 8 years ago

tastywheat commented 8 years ago

I can't seem to find any documentation which explains how to decode a list of find results. So far I have a list of Mongo.Response, but I have no idea where to go from here:

# Connect the mongo server (by default port 27017 at 127.0.0.1)
        mongo = Mongo.connect!
        # Select the db to access
        db = mongo |> Mongo.db("test")
        # Select the db to access
        articles = db |> Mongo.Db.collection("articles")

        articles
            |> Mongo.Collection.find
            # |> Map.put(:batchSize, 4)
            |> Mongo.Find.exec
            |> Enum.to_list
            |> Enum.map fn doc -> Mongo.Response.bson_decode(doc.buffer) end
            |> IO.inspect
jerp commented 8 years ago

please try

Mongo.connect! |> Mongo.db("test") |> Mongo.Db.collection("articles") |> Mongo.Collection.find |> Enum.to_list
tastywheat commented 8 years ago

I'm doing this:

articles
            |> Mongo.Collection.find
            |> Mongo.Find.exec
            |> Enum.to_list
            |> IO.inspect

Then getting back a binary response:

[%Mongo.Response{buffer: <<216, 5, 0, 0, 2, 95, 105, 100, 0, 10, 0, 0, 0, 120, 118, 90, 99, 114, 108, 70, 87, 121, 0, 2, 115, 111, 117, 114, 99, 101, 65, 114, 116, 105, 99, 108, 101, 85, 114, 108, 0, 114, 0, 0, 0, 104, 116, 116, ...>>,
  cursorID: 8803432542, decoder: &Mongo.Response.bson_decode/1, nbdoc: 101,
  requestID: 1303776868, startingFrom: 0},
 %Mongo.Response{buffer: <<36, 21, 0, 0, 2, 95, 105, 100, 0, 10, 0, 0, 0, 118, 111, 68, 116, 88, 78, 83, 65, 109, 0, 2, 115, 111, 117, 114, 99, 101, 83, 105, 116, 101, 0, 20, 0, 0, 0, 119, 119, 119, 46, 97, 115, 105, 97, 110, ...>>,
  cursorID: 0, decoder: &Mongo.Response.bson_decode/1, nbdoc: 272,
  requestID: 1199601926, startingFrom: 101}]

What am I supposed to do with this?

jerp commented 8 years ago

Please try the following

 Mongo.connect! |> Mongo.db("test") |> Mongo.Db.collection("anycoll") |> Mongo.Collection.find |> Enum.to_list

On 16 Dec 2015, at 01:24, tastywheat <notifications@github.com mailto:notifications@github.com> wrote:

I'm doing this:

articles |> Mongo.Collection.find |> Mongo.Find.exec |> Enum.to_list |> IO.inspect

Then getting back a binary response:

[%Mongo.Response{buffer: <<216, 5, 0, 0, 2, 95, 105, 100, 0, 10, 0, 0, 0, 120, 118, 90, 99, 114, 108, 70, 87, 121, 0, 2, 115, 111, 117, 114, 99, 101, 65, 114, 116, 105, 99, 108, 101, 85, 114, 108, 0, 114, 0, 0, 0, 104, 116, 116, ...>>, cursorID: 8803432542, decoder: &Mongo.Response.bson_decode/1, nbdoc: 101, requestID: 1303776868, startingFrom: 0}, %Mongo.Response{buffer: <<36, 21, 0, 0, 2, 95, 105, 100, 0, 10, 0, 0, 0, 118, 111, 68, 116, 88, 78, 83, 65, 109, 0, 2, 115, 111, 117, 114, 99, 101, 83, 105, 116, 101, 0, 20, 0, 0, 0, 119, 119, 119, 46, 97, 115, 105, 97, 110, ...>>, cursorID: 0, decoder: &Mongo.Response.bson_decode/1, nbdoc: 272, requestID: 1199601926, startingFrom: 101}] What am I supposed to do with this?

— Reply to this email directly or view it on GitHub https://github.com/checkiz/elixir-mongo/issues/30#issuecomment-164942557.

CharlesIrvineKC commented 8 years ago

Being new to both Mongo and Elixir, I too could use a little documentation of some sort. Perhaps add examples to the API docs at http://checkiz.github.io/elixir-mongo/