Generate Json x Search in mongodb

Asked

Viewed 44 times

2

I’m generating a Json.

But I have the following situation:

I have a record of contacts who may belong to the same company. I mean, I can have two people registered in a single company.

How do I load these contacts into my json?

I’m doing it this way:

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

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

  • The ID on Mongodb is unique, so because Id can’t find more than one, just try using Contact.find with any information you have..

1 answer

1

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

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

Or:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.