有時候分布式集群正在遷移數據,它導致count統計結果錯誤, 請問如何解決?
-
有時候分布式集群正在遷移數據,它導致count統計結果錯誤, 請問如何解決?
-
使用aggregate pipeline來得到正確統計結果,例如:
db.collection.aggregate([{$group: {_id: null, count: {$sum: 1}}}])
引用:「On a sharded cluster, count can result in an inaccurate count if orphaned documents exist or if a chunk migration is in progress.」