的內部陣列我有一個文件是這樣的:MongoDB的篩選對象
-document: users-
{
"name": "x", password: "x" recipes:
[{title: eggs, dificult: 1},{title: "pizza" dificult: 2}],
name: "y", password: "y" recipes: [{title: "oil", dificult: 2},{title: "eggandpotatoes" dificult: 2}]
}
我想所有的食譜由標題和難治過濾
我已經嘗試了一些類似這樣的
db.users.find({$and: [{"recipes.title": /.*egg.*/},{"recipes.dificult": 2}]},
{"recipes.title": 1,"recipes.dificult": 1}).toArray();
這應該返回
{title: "eggandpotatoes" dificult: 2}
但返回
{title: eggs, dificult: 1}
{title: "eggandpotatoes" dificult: 2}
我願再次過濾器的工作原理,限制與開始結果:2和端部:5 從2結果返回提前在未來5
感謝。