[英]Elixir streaming mondodb fail
我正在使用elixir-mongo並嘗試流式傳輸查詢結果。 這是代碼...
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
)
結束
所有的子位似乎都可以工作(就像查詢一樣),但是當我嘗試獲取流時,我失敗了...
Mdb.archive_stream({jobs, {{2013,11,1},{0,0,0}}})|>Enum.take(2)
我知道了
(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
我很沮喪 有任何想法嗎? 謝謝您的幫助
ang! 新秀錯誤。
:halt -> {:halt, {cont, therest, c}}
應該是:halt -> {:halt, {cont, therest, c}}
_ -> {:halt, z}
和fn(:halt, resp) -> resp end
應該是fn(resp) -> resp end
我一直在忙着一個半天,除了after函數。
對其他新手的更多解釋...
_
以捕獲其他“不良行為”,而不僅僅是{:halt} z
元組。 它不希望看到:halt
和z
,只是z
。 希望得到REAL專家的意見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.