I am using Meteor, and I want to get a list of contacts: - each contacts has an id, - I want to search the DB for all the user to see if I find matching IDs, - if I find them I need to: a) update my contact[i] b) update the found ID with my personal ID
The problem with this is that I don't manage [so far] to do this operation with Mongo.
Full post is here https://forums.meteor.com/t/connecting-users-mongo-strategy/4132
Code here:
for (var i = 0;i < contacts.length; i++) {
Meteor.users.find({"profile.phone": contacts[i].phone}).forEach(function(friend){
console.log('We found a friend', friend);
contacts[i].appActive = true;
contacts[i].appId = friend._id;
Meteor.users.update({_id: friend._id}, { $addToSet: { "profile.friends": Meteor.userId() }});
});
}
The logic is sound, the problem is with HOW I understand Mongo [poorly], I'm guessing the queries are async, I'm trying to create a cursor with find on the server side but I'm stuck.
Any pointer are appreciated. Thanks!