Search comparing id of two Collections

Asked

Viewed 63 times

0

I need to load the data by joining two id

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

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

When I do:

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

doesn’t work.

1 answer

0

Maybe you don’t understand what you want, but if contact.Client.id and client.id are equal, the query you want is:

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

If they are different and you want both documents referenced:

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

Browser other questions tagged

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