Generate Json x Search on mongodb

2

I'm generating a Json.

But I have the following situation:

I have a contact record that can belong to the same company. That is, I can have two people registered in a single company.

How do I load these contacts into my json?

I'm doing the following:

Contato.findById(contato.Cliente.id,function(err, contatos) {  
             //aqui carrego as informacoes. 

But it only carries the last registered contact, and I need to bring all.

    
asked by anonymous 25.06.2015 / 14:47

1 answer

1

You should search for contacts that have references to related documents.

Contato.find({ client_id: client_id }, function(err, contatos) {
// ...
});

Or:

Contato.find({ company_id: company_id }, function(err, contatos) {
// ...
});
    
01.09.2015 / 00:35