In mongoDB, how do I implement a query as complex as I described?

question background description:
an online examination system. When designing a database to store test questions,
if you use a collections to store basic questions, medium-range questions, and high-level problems,
store them by setting the properties type:easy or medium or hard of each instance, as shown in the following table:

"title" : "javascript", 
"choose" : "A.boolen B.string C.function ", 
"true" : "C",
"type" : "easy" 

now I want to randomly query 20 type:easy questions. How to write the query sentence?
already know that the random query function has been added in version 3.2

.
db.questions.aggregate(
   { $sample: { size: 20 } }
)

but in my test questions database, there are not only simple questions, but also medium-range questions and high-level problems.
how can I randomly query 20 questions from simple questions?
there is another problem. Even though version 3.2 adds aggregate operation, mongoose does not seem to support this operation
. If you use mongoose, how can you achieve the effect in the question? T.T

Mar.05,2021

has been resolved..
scenario one. When inserting a test question, define a self-increasing index, and then use random* to collect the total number of data, and use this to find,find several times is to take a few random numbers.
solution 2. The new aggregation (aggregate) method in MongoDB 3.2 uses $match (Filter data) and $sample (take random numbers) to achieve the effect.

Menu