Search comparing id of two collections

0

I need to load the data by joining two id

In a form, I populate my client with an ID. In another form I fill in other information and load the customer ID. That is, both forms send the same ID to the bank.

I need to generate a json that has the information for these two forms.

When I do:

Contact.findOne({$and: [{_id: contact.Client.id}, {_id: client.id}]},function(err, contacts) {

does not work.

    
asked by anonymous 24.06.2015 / 21:01

1 answer

0

Maybe you do not understand what you want, but if contact.Client.id and client.id are the same, the query you want is:

Contact.findOne({ _id: contact.Client.id }, /*...*/)

If they are different and you want both referenced documents:

Contact.find({ $or: [ { _id: contact.Client.id }, { _id: client.id } ] }, /*...*/)
    
31.08.2015 / 15:53