Mongodb $sample (aggregation)

jathazp·2022년 3월 5일
0

$sample (aggregation)
컬렉션 내에서 $sample - size 개수만큼 랜덤하게 가져오기

{ $sample: { size: <positive integer N> } }
ex)

// randomly selects 3 documents from the collection:
db.users.aggregate([ { $sample: { size: 3 } } ])
   
              
//result
{ "_id" : 2, "name" : "dave2", "q1" : false, "q2" : false  }
{ "_id" : 3, "name" : "ahn", "q1" : true, "q2" : true  }
{ "_id" : 7, "name" : "ty", "q1" : false, "q2" : true  }

ref) https://docs.mongodb.com/manual/reference/operator/aggregation/sample/

0개의 댓글