casbah游标和toList [英] casbah cursor and toList

查看:88
本文介绍了casbah游标和toList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在casbah中有一个游标,它是从查询返回的.如果我在游标上进行迭代,则会得到一定数量的结果x.如果我执行相同的查询并在游标上执行toList,则会得到大小为y的列表,该列表是一个不同的数字.为什么?

I have a cursor in casbah, returned from a query. If I iterate over the cursor I get a certain number of results, x. If I execute the same query and do a toList on the cursor, I get list of size y, a different number. Why?

我从一个使用默认WriteConcern将几百行写入集合的测试用例中调用此方法.我知道写入可能会有些延迟.我不理解的是游标的大小不同:我迭代vs toList.他们基本上不是在做同样的事情(假设我从我的迭代中得到一个列表)吗?

I'm calling this from a test case that has just wriiten a few hundred rows to the collection using the default WriteConcern. I understand there could be some latency with the write. What I don't understand is the different sizes of the cursor: I iterate vs toList. Aren't they basically doing the same thing (presuming I'm yielding a List from my iteration)?

val cur = findCursor(query, orderBy).skip(skip).limit(chunkSize * -1) // results size x if I iterate cur
val ret = cur.toList.map( dbo => SJ.readDB[T](dbo) ). // List size y here after toList

推荐答案

发现问题.问题在于传递给限制功能的负值.我不完全了解要限制的pos/neg值之间的语义差异,也不知道为什么它们会返回不同的计数,但是切换为正数会返回预期的结果计数.

The problem was found. The issue lay with the negative value passed to the limit function. I don't fully understand the semantic difference between pos/neg values to limit, or why they'd return different counts, but switching to a positive number returned the result count expected.

这篇关于casbah游标和toList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆