У меня есть массивMongoDB матч документы со всеми элементами в данном массиве
solvedProblemIds = [0,2]
и я хочу, чтобы запросить документы, имеющие все элементы в их requiredProblems массива внутри массива solvedProblemIds.
, например, если это мои документы:
{
id: 0,
name: "Problem 1",
points: 10,
description: "Problem 1 desc",
requiredProblems: []
},
{
id: 1,
name: "Problem 2",
points: 10,
description: "Problem 2 desc",
requiredProblems: [0]
},
{
id: 2,
name: "Problem 3",
points: 10,
description: "Problem 3 desc",
requiredProblems: [0]
},
{
id: 3,
name: "Problem 4",
points: 10,
description: "Problem 4 desc",
requiredProblems: [0, 2]
},
{
id: 4,
name: "Problem 5",
points: 10,
description: "Problem 5 desc",
requiredProblems: [0, 1, 2, 3]
}
запрос должен соответствовать документам с идентификатором 3, 2, 1 и 0. Я посмотрел на $ в селекторе, но она требует только Один элемент, который должен быть в массиве, не все.
Возможный дубликат [Найти документы в MongoDB, чье поле массива является подмножеством массива запросов] (http://stackoverflow.com/questions/16109351/find-documents-in-mongodb-whose-with-an -array-field-is-a-subset-of-a-query-array) – mohi