2017-06-15 4 views
1
//PhoneProduct is model 
//My schema has brand field with string type 
var brands = ['apple', 'samsung']; 
var QueryResult = PhoneProduct.find().where('brand').equals(brands)); 

ブランドアレイのどの要素と同等のブランドを持つドキュメントを取得する方法はありますか?あなたはそれが配列から所属するかどうかを確認する必要があり、このためにあなたは、配列の文字列をcampareすることはできませんmongodbの文字列と文字列を比較する方法問い合わせ条件

+0

まあ[ '$ in'](HTTPSを試してみてください://ドキュメント.mongodb.com/manual/reference/operator/query/in /)を参照してください。 [Mongooseにもヘルパーがいます。] 'QueryResult = PhoneProduct.find()。ここで( 'brand')。in(brands)' –

+0

ありがとう。あなたのコードは動作します。私は上記のコードをテストし、それも動作します。 –

答えて

0
var QueryResult = PhoneProduct.find({'brand': {$in: brands }}) 
0

は、 はこの

//PhoneProduct is model 
//My schema has brand field with string type 
var brands = ['apple', 'samsung']; 
var QueryResult = PhoneProduct.find({brand: {$in: brands}}) 
関連する問題