mongodb - mongo-mongoose how to make this query mongoose? -


models

models -> id, name, makeid

makes -> id, name

how make query mongoose using make name , not id ("mitsubishi") ?ex:

select * models left join makes on models.makeid = makes.id makes.name = "mitsubishi" 

how can realize same query in mongo - mongoose ?

if model schema, written so:

makeid: {type: schema.types.objectid, ref: 'makes'} 

then can population query so:

model.findone({}).populate( {path:'makeid'}); 

this return object looks this:

{id:'mirage', 'name':'mirage', makeid:{id:'mitsubishi', name:'mitsubishi'}} 

i name "makeid" field of model "make" make more idiomatic.

you'd _id , other properties. if want filter properties add select property:

{path:'makerid', select:'id name'} 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -