Mongoose根据数据库数组中项目的值select结果

我有一个模式字段(价格)是一个数组,通常只有1个价格,但有时销售价格列为数组中的第二个项目。

我希望能够查询这个领域,并返回所有的产品,从最低到最高sorting(而我在它,使用$ GT和$ LT按范围select)。

但我的挑战是处理销售价格,这是我arrays中的第二个价值。 我需要能够按这个价格来分类,而不是第一个价格,如果实际上有一个销售价格的话。 我不知道如何说“如果(价格[1]){使用价格[1]}在我的mongoose查询。

UPDATE

我能够使用下面的查询几乎得到我想要的。
我的问题是,当我把price.1放在第一位的时候(这些部分是用$来划分的),我只能得到反映价格产品的结果。 当我第一个放置第二个,那个价格是真的时,我只会得到相反的, 没有价格的产品。

mongoose只读我的查询的第二部分?

Product.find({ $and: [{"price.1": {$exists : false }}, {"price.0": {$gte : req.body.lower_price}}, {"price.0": {$lte : req.body.higher_price} }], $and : [{"price.1": {$exists: true}}, {"price.1": {$gte : req.body.lower_price}}, {"price.1": {$lte : req.body.higher_price} }]}) .exec(function(err, products){ if(err){ console.log(err) } else{ res.send(products) } }); 

 Model.find({$or :[{"price.1": {$exists: false}}, {"price.1": {$gt : 10}}]}) //get all documents where either second element of the price array doesn't exist OR if it does it's greater than 10 .sort("price.1") // asc. Docs without second element will come first. Use -price for desc .exec(function(err, res){ if(err){ console.log(err) } else{ console.log(res) } });