MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

Como agregar um array enorme no mongoDB?


Tente isto:
db.users.aggregate( 
 [ 
  { $unwind : "$key" }, 
  { $group : { _id : "$key", number : { $sum : 1 } } },
  { $sort : { number : -1 } }, 
  { $limit : 10000 },
  { $out:"result"},
 ], {
  allowDiskUse:true,
  cursor:{}
 }
);

Em seguida, encontre o resultado por db.result.find() .