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