I am using the $sample query for mongo aggregation. in the following manner:
db.col.aggregate([
{$match: {topic: topic}},
{$sample: {'size': 10}}
{$project: {_id: 1}}
])
My question is, is there a way to set the 'seed' for the sampling, so that every time I run this command I get the same result ?
For example, in python I do it like the following:
import random
list_of_items = [...]
# set the seed to 0
random.seed(0)
# get sample
samples = random.sample(list_of_items, 10)
By manually defining the seed, I make sure that the result is the same every time I do this operation.
_id
values and supply those with an$in
query instead. – Bedspring