Categories
Mongodb selecting random documents?
How can you get random documents from a collection using filters? i.e. how can you get random documents with such a request? find({ "tag": "test" })
Answer the question
In order to leave comments, you need to log in
https://docs.mongodb.com/manual/reference/operator... something like this
db.posts.aggregate([ { $match: { "tag": "test" } }, { $sample: { size: 3 } } ])
Didn't find what you were looking for?
Ask a Question
731 491 924 answers to any question