【问题标题】:Elixir streaming mondodb failElixir 流式传输 mongodb 失败
【发布时间】:2015-03-21 11:43:28
【问题描述】:

我正在使用 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 使用 1 个参数调用 arity 2 ({:cont, >, %Mongo.Cursor{batchSize: 0, 集合: %Mongo.Collection {db: %Mongo.Db{auth: {"admin", "edd5404c4f906060b125688e26ffb281"}, mongo: %Mongo.Server{host: 'db-stage.member0.mongolayer.com', id_prefix: 57602, mode: :passive,选择:%{},端口:27017,套接字:#Port,超时:6000},名称:“db-stage”,选择:%{模式::被动,超时:6000}},名称:“工作", opts: %{}}, 用尽: false, response: %Mongo.Response{buffer: >, cursorID: 3958284337526732701, 解码器: &Mongo.Response.bson_decode /1,nbdoc:101,requestID:67280413,startingFrom:0}}}) (长生不老药) lib/stream.ex:1020: Stream.do_resource/5 (长生不老药) lib/enum.ex:1731: Enum.take/2

我被难住了。有任何想法吗? 感谢您的帮助

【问题讨论】:

    标签: mongodb stream elixir


    【解决方案1】:

    当!新手错误。

    :halt -> {:halt, {cont, therest, c}} 应该是 _ -> {:halt, z}fn(:halt, resp) -> resp end 应该是 fn(resp) -> resp end

    一天半以来,我一直在琢磨除了 after 函数之外的所有东西。

    给小伙伴们多解释一下……

    • next_fun() 中的最后一个选项应该是 _ 以便捕捉其他“不良行为”,而不仅仅是 {:halt}
    • after_fn() 只需要 1 个 arg,在上面的代码中,next_fun() 的最后一个选项中的 z 元组。预计不会看到:haltz,只是z

    希望得到真正的专家意见。

    【讨论】:

    • 你可以接受你自己的答案,这样问题就会被列为已解决:)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 2016-09-29
    相关资源
    最近更新 更多