Mongo $ sample在某些机器上失败

时间:2018-10-08 20:05:59

标签: mongodb aggregation-framework

在开发机上,$sample查询工作正常。 在生产机器上,它会失败。

这是一个非常简单的查询,可以从集合中获取一些随机元素。
没有其他agg管道命令。

有什么建议可以看吗?
Goog提出了其他一些问题,但没什么。

  • 开发人员机器:Mac v3.6.5
  • 产品机器:Ubuntu v3.6.7

  • 错误:

$sample stage could not find a non-duplicate document after 100 while using a random cursor

代码:

let grams = await GramsModel.coll.aggregate(
  [
    { $sample: { size: 2 } }
  ]
).toArray()

日志

@random.rikai-bots.com 279|tutorw | MongoError: $sample stage could not find a non-duplicate document after 100 while using a random cursor. This is likely a sporadic failure, please try again.
@random.rikai-bots.com 279|tutorw |     at Function.MongoError.create (/opt/rikai/web-apps/tutorweb/node_modules/mongodb-core/lib/error.js:31:11)
@random.rikai-bots.com 279|tutorw |     at queryCallback (/opt/rikai/web-apps/tutorweb/node_modules/mongodb-core/lib/cursor.js:212:36)
@random.rikai-bots.com 279|tutorw |     at /opt/rikai/web-apps/tutorweb/node_modules/mongodb-core/lib/connection/pool.js:469:18
@random.rikai-bots.com 279|tutorw |     at process._tickCallback (internal/process/next_tick.js:61:11)
@random.rikai-bots.com 279|tutorw | Mon, 08 Oct 2018 20:00:33 GMT server 

该错误不是偶发性的-100%发生在Ubuntu / 3.6.7上,从未发生在Mac / 3.6.5上

否则,我只需要编写我自己的使用偏移量或类似内容的随机项func ...

0 个答案:

没有答案
相关问题