I used this https://github.com/ankhers/mongodb driver to run queries on my Elixir application.
The doc specifies that the Mongo.find(...)
function returns specified fields with projection
option. But, when I try to pass the required field in projection, I get the following error:
** (Protocol.UndefinedError) protocol Enumerable not implemented for "ques_text". This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Mongo.AggregationCursor, Mongo.Cursor, Mongo.SinglyCursor, Postgrex.Stream, Range, Stream, Timex.Interval
My query looks like this:
Mongo.find(:mongo, "questions", %{"no_of_options": 4}, [projection: "ques_text", limit: 1])
And I can see the ques_text
field under select
field of %Mongo.Cursor
.
Is that a wrong way to pass projection option? I am new to Elixir.
[projection: %{"ques_text" => 1}, limit: 1]
? – Dogbert