سؤال

this is on mongodb

{cod_com:'WWWOAN',
     cod_prod[{prod:'proda',info:'hola mundo'},{prod:'pacda',info:'hola mundo'},{prod:'prcdb',info:'hola mundo'}]
}
{cod_com:'WWWOA2',
     cod_prod[{prod:'prdda',info:'hola mundo'},{ccod:'prcda',info:'hola mundo'}]
}
{cod_com:'WWWOA1',
     cod_prod[{prod:'prcda',info:'hola mundo'},{aaad:'prcda',info:'hola mundo'}]
}

i have to get the info inside the cod_prod variables... so im working with two steps

first i query the owner of the cod_prod

db.collection.findOne({cod_com:'WWWOA1'});

if exists, i query the cod_prod that i need

db.collection.findOne({'cod_prod.prod':'prcda'});

so basically im querying two times, first is to the the owner of the product, and the second the info of the product that im searching...

the question is, there is any way to search the prod directly???

i cant use this...

db.collection.findOne({'cod_prod.prod':'prcda'});

because differents owners has same product... so first i get the owner and second i get the product....

anybody has a better aproach?? or a different way to get the info??? tnx

هل كانت مفيدة؟

المحلول

If you query like this:

db.collection.findOne({'cod_com':'WWOA1', 'cod_prod.prod':'prcda'});

you should get the result you want.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top