Eli*_*Eli 5 mongoose mongodb node.js
我正在将我的应用程序从Mongoose 2.6.5迁移到3.1.2,并且我遇到了一些意想不到的行为.也就是说,我注意到查询结果自动限制为1000条记录,而其他所有内容的工作方式都相同.在我的代码(下面)中,我设置了一个值maxIvDataPoints,该值限制了返回的数据点的数量(并最终发送到客户端浏览器),并且该值在别处设置为1500.我使用计数查询来确定潜在结果的总数,然后是一个后续的mod来限制实际的查询结果,使用count和value maxIvDataPoints来确定mod的值.我正在运行节点0.8.4和mongo 2.0.4,在coffeescript中编写服务器端代码.
在安装mongoose 3.1.x之前,代码按照我的意愿工作,每次返回的数据点不到1500.安装3.1.2后,我每次都会返回1000个数据点(假设指定范围内有超过1000个数据点).结果被截断,因此数据点1001到~1500是不再返回的数据点.
似乎某些设置可能会控制此行为,但我无法在文档,此处或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()
Run Code Online (Sandbox Code Playgroud)
你会被一对相关因素绊倒:
所以你的选择是在它上面放一个组合索引TestDataPoint,允许mongo dataPoint在这种类型的查询中使用它进行排序,或者将批量大小增加到至少你期望的文档总数.
哇,太糟糕了。我将很快发布对 mongoose 的修复,删除默认的默认批量大小(在流式传输大型结果集时很有帮助)。谢谢指点。
更新:3.2.1 和 2.9.1 已发布并修复(删除了默认的批量大小)。
| 归档时间: |
|
| 查看次数: |
5309 次 |
| 最近记录: |