1、Distinct聚合查询报错

db.users.distinct("uname")
db.runCommand({"distinct":"users","key":"uname"})
在数据量很大的时候,使用这种方法查询时,查询的结果集大于16M 时会查询失败,失败信息如下: 
比如要对名字字段name进行distinct
db.XX.distinct('imsi')
报错如下:
 [main] Error: distinct failed: {
    "ok" : 0,
    "errmsg" : "distinct too big, 16mb cap",
    "code" : 17217,
    "codeName" : "Location17217"
} :
 
MongoDB 聚合查询报错

 

解决办法:改成用聚合方式

db.XX.aggregate([{$group:{_id:{'imsi':"$imsi"},count:{$sum:1}}}],{ allowDiskUse: true})
 

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2021-05-30
  • 2021-08-01
  • 2022-12-23
  • 2022-01-15
猜你喜欢
  • 2022-01-04
  • 2021-12-25
  • 2021-06-24
  • 2021-10-07
  • 2021-09-04
相关资源
相似解决方案