0

这是架构:

var userschema = new mongoose.Schema({

   user: String,
   pass: String,
   imagen: [{ 

              title: String,
              author: String,
              description: String,
              index: Number,
              path: String,

           }]

});

我正在尝试使用 'foomodel.find',在 Schema 的 imagen 数组中查找具有特定属性的元素,我的意思是:

usermodel.find({ user: foo, 'imagen.index': 1 }, function (err, imagen){

        if(err) throw err;

        console.log(imagen);

});

在控制台中,我收到了 this [],当我想收到 imagen 数组元素的属性时,它的索引为 1。我检查了它是否存在。有什么解决办法...?

谢谢提前!

4

1 回答 1

0

我认为您需要使用$elementMatch

usermodel.find({ user: foo, "imagen": {"$elemMatch":{"index": 1 }}, 
    function (err, imagen){
        if(err) throw err;
        console.log(imagen);
});
于 2013-01-08T21:24:23.923 回答