2014-04-16 29 views
8

Ben nasıl anlamaya çalışıyorum iç içe VEYA/VE MySQLMongoDB İç içe geçmiş OR/AND Nerede?

ne yapacağını gibi sorgular örnek

SELECT 
    first_name, 
    id 
FROM 
    table 
WHERE 
    (
     province = "nb" OR 
     province = "on" 
    ) AND (
     city = "toronto" AND 
     first_name = "steven" 
    ) 

cevap

17

alalım nerede MongoDB sorgu benziyor:

Database.collection_name.find(
    // This is the condition 
    { 
     $and: [ 
      { 
       $or: [ 
        {province: 'nb'}, 
        {province: 'on'} 
       ] 
      }, 
      { 
       city: "toronto" 
      }, 
      { 
       first_name: "steven" 
      } 
     ] 
    }, 

    // Specify the fields that you need 
    { 
     first_name: 1, 
     _id: 1 
    } 
) 

$and$or

Bazı örnekler için Dokümantasyon ve MongoDB için resmi belgeler here'u bulun.

+0

Sorunuz için tam sorguyu içerecek şekilde cevabı düzenledim. –

İlgili konular