Mongoose限制查询1000结果,当我想要更多/所有(从2.6.5迁移到3.1.2)

我将我的应用程序从Mongoose 2.6.5迁移到3.1.2,并且遇到了一些意想不到的行为。 即我注意到,查询结果自动被限制为1000条logging,而几乎所有的东西都是一样的。 在我的代码(下面)中,我设置了一个值maxIvDataPoints ,它限制了返回的数据点的数量(最终发送到客户端浏览器),并将该值设置为1500.我使用计数查询来确定总数结果,然后使用计数和maxIvDataPoints的值来限制实际查询结果的后续mod,以确定mod的值。 我正在运行节点0.8.4和mongo 2.0.4,在coffeescript中编写服务器端代码。

在安装mongoose 3.1.x之前,代码正常工作,每次只返回1500个数据点。 安装完3.1.2后,我每次都得到1000个数据点(假设指定范围内有1000个以上的数据点)。 结果被截断,所以数据点1001到~1500不再被返回。

似乎可能会有一些设置在某个地方来支配这种行为,但我无法在文档中find任何内容,在此处或在Google小组中。 我仍然是一个相对n00b,所以我可能错过了一些明显的东西。

 DataManager::ivDataQueryStream = (testId, minTime, maxTime, callback) -> # If minTime and maxTime have been provided, set a flag to limit time extents of query unless isNaN(minTime) timeLimits = true # Load the max number of IV data points to be displayed from CONFIG maxIvDataPoints = CONFIG.maxIvDataPoints # Construct a count query to determine the number if IV data points in range ivCountQuery = TestDataPoint.count({}) ivCountQuery.where "testId", testId if timeLimits ivCountQuery.gt "testTime", minTime ivCountQuery.lt "testTime", maxTime ivCountQuery.exec (err, count) -> ivDisplayQuery = TestDataPoint.find({}) ivDisplayQuery.where "testId", testId if timeLimits ivDisplayQuery.gt "testTime", minTime ivDisplayQuery.lt "testTime", maxTime # If the data set is too large, use modulo to sample, keeping the total data series # for display below maxIvDataPoints if count > maxIvDataPoints dataMod = Math.ceil count/maxIvDataPoints ivDisplayQuery.mod "dataPoint", dataMod, 1 ivDisplayQuery.sort "dataPoint" #, 1 <-- new sort syntax for Mongoose 3.x callback ivDisplayQuery.stream() 

你被一对相关的因素绊倒了:

  1. Mongoose的默认查询batchSize 在3.1.2中改为1000 。
  2. MongoDB有一个已知的问题 ,即需要进行内存sorting的查询会将查询的批量大小限制在返回的文档数量上。

因此,您的select是在TestDataPoint上放置一个组合索引,这将允许mongo在此类查询中使用它进行dataPointsorting,或将批量大小增加到至less您所期望的文档总数。

哇,这太可怕了。 我将马上发布一个修复程序到mongoose,删除batchSize默认值(在stream式处理大型结果集时很有帮助)。 感谢指针。

更新 :3.2.1和2.9.1已经发布与修复(删除batchSize默认)。