[英]Elixir streaming mondodb fail
I am using elixir-mongo and trying to stream the results of a query. 我正在使用elixir-mongo并尝试流式传输查询结果。 Here's the code...
这是代码...
def archive_stream(z) do
Stream.resource(
fn ->
{jobs, datetime} = z
lt = datetime_to_bson_utc datetime
c = jobs |> Mongo.Collection.find( %{updated_at: %{"$lt": lt}}) |> Mongo.Find.exec
{:cont, c.response.buffer, c}
end,
fn(z) ->
{j, {cont, therest, c}} = next(z)
case cont do
:cont -> {j, {cont, therest, c}}
:halt -> {:halt, {cont, therest, c}}
end
end,
fn(:halt, resp) -> resp end
)
end 结束
All of the sub-bits seem to work (like the query), but when I try to get at the stream, I fail... 所有的子位似乎都可以工作(就像查询一样),但是当我尝试获取流时,我失败了...
Mdb.archive_stream({jobs, {{2013,11,1},{0,0,0}}})|>Enum.take(2)
I get... 我知道了
(BadArityError) #Function<2.49475906/2 in Mdb.archive_stream/1> with arity 2 called with 1 argument ({:cont, <<90, 44, 0, 0, 7, 95, 105, 100, 0, 82, 110, 129, 221, 102, 160, 249, 201, 109, 0, 137, 233, 4, 95, 115, 108, 117, 103, 115, 0, 51, 0, 0, 0, 2, 48, 0, 39, 0, 0, 0, 109, 97, 110, 97, 103, 101, 114, 45, ...>>, %Mongo.Cursor{batchSize: 0, collection: %Mongo.Collection{db: %Mongo.Db{auth: {"admin", "edd5404c4f906060b125688e26ffb281"}, mongo: %Mongo.Server{host: 'db-stage.member0.mongolayer.com', id_prefix: 57602, mode: :passive, opts: %{}, port: 27017, socket: #Port<0.27099>, timeout: 6000}, name: "db-stage", opts: %{mode: :passive, timeout: 6000}}, name: "jobs", opts: %{}}, exhausted: false, response: %Mongo.Response{buffer: <<188, 14, 0, 0, 7, 95, 105, 100, 0, 82, 110, 129, 221, 102, 160, 249, 201, 109, 0, 137, 242, 4, 95, 115, 108, 117, 103, 115, 0, 45, 0, 0, 0, 2, 48, 0, 33, 0, 0, 0, 114, 101, 116, 97, ...>>, cursorID: 3958284337526732701, decoder: &Mongo.Response.bson_decode/1,
(BadArityError)#Function <2.49475906 / 2 in Mdb.archive_stream / 1>中,使用第1个参数调用了Arity 2({:cont,<< 90,44,0,0,7,95,105,100,0,82, 110、129、221、102、160、249、201、109、0、137、233、4、95、115、108、117、103、115、0、51、0、0、0、2、48, 0,39,0,0,0,109,97,110,97,103,101,114,45,... >>,%Mongo.Cursor {batchSize:0,collection:%Mongo.Collection {db: %Mongo.Db {auth:{“ admin”,“ edd5404c4f906060b125688e26ffb281”},mongo:%Mongo.Server {host:'db-stage.member0.mongolayer.com',id_prefix:57602,模式::passive,opts:% {},端口:27017,套接字:#Port <0.27099>,超时:6000},名称:“ db-stage”,选择:%{mode :: passive,超时:6000}},名称:“ jobs”,选择:%{}},已用尽:错误,响应:%Mongo.Response {缓冲区:<< 188、14、0、0、7、95、105、100、0、82、110、129、221、102、160 ,249、201、109、0、137、242、4、95、115、108、117、103、115、0、45、0、0、0、2、48、0、33、0、0、0 ,114,101,116,97,... >>,cursorID:3958284337526732701,解码器:&Mongo.Response.bson_decode / 1, nbdoc: 101, requestID: 67280413, startingFrom: 0}}}) (elixir) lib/stream.ex:1020: Stream.do_resource/5 (elixir) lib/enum.ex:1731: Enum.take/2
nbdoc:101,requestID:67280413,startingFrom:0}}})(elixir)lib / stream.ex:1020:Stream.do_resource / 5(elixir)lib / enum.ex:1731:Enum.take / 2
I'm stumped. 我很沮丧 Any ideas?
有任何想法吗? thanks for the help
谢谢您的帮助
Dang! ang! Rookie Error.
新秀错误。
:halt -> {:halt, {cont, therest, c}}
should be _ -> {:halt, z}
and fn(:halt, resp) -> resp end
should be fn(resp) -> resp end
:halt -> {:halt, {cont, therest, c}}
应该是:halt -> {:halt, {cont, therest, c}}
_ -> {:halt, z}
和fn(:halt, resp) -> resp end
应该是fn(resp) -> resp end
I've been d**king around with everything but the after function for a day and a half. 我一直在忙着一个半天,除了after函数。
A little more explanation for fellow rookies... 对其他新手的更多解释...
_
inorder to catch other "bad behavior" and not just {:halt} _
以捕获其他“不良行为”,而不仅仅是{:halt} z
tuple in the last option of the next_fun(). z
元组。 It is not expecting to see :halt
and z
, just z
. :halt
和z
,只是z
。 Would like to have REAL experts input. 希望得到REAL专家的意见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.