javascript - Match 2 fields in different records Mongoose -


goodmorning

i trying match fields on dataset. dataset contains records like:

{     "token" : "17e0d95f2e2112443cfb09970ae9140e",     "answers" : {         "yourname" : "marco",         "youremail" : "marco@me.nl",         "recemail" : "sonja@me.nl"     } },   {     "token" : "cf5ae65b05249dc6b2a0c99c4cf9688e",     "answers" : {         "yourname" : "sonja",         "youremail" : "sonja@me.nl",         "recemail" : "marco@me.nl"     } } 

in case, should match 2 because recemail (recipients email) matches else's email address. , vice versa. trying find how find these 2 records (in larger dataset more of these matches).

so, marco's recemail should find sonja's youremail , these 2 matches should made available save collection, that's not important part here.

hope can me query thanks!

the following code return array of 2-entry arrays. each 2-entry array made of sender email , recipient email. each pair appear once. in other words, you'll ["marco@me.nl", "sonja@me.nl"] not ["sonja@me.nl", "marco@me.nl"].

var list = [{      "token" : "17e0d95f2e2112443cfb09970ae9140e",      "answers" : {          "yourname" : "marco",          "youremail": "marco@me.nl",          "recemail" : "sonja@me.nl" }    }, {      "token" : "cf5ae65b05249dc6b2a0c99c4cf9688e",      "answers" : {          "yourname" : "sonja",          "youremail": "sonja@me.nl",          "recemail" : "marco@me.nl" }    }, {      "token" : "fe2c2740e083dfe02cc7e96520a0e079",      "answers" : {          "yourname" : "joe",          "youremail": "joe@foo.com",          "recemail" : "mike@bar.com" }    }  ];    var res = [], sz = list.length;    list.foreach(function(obj, pos) {    for(var = pos + 1; < sz; i++) {      if(        list[i].answers.youremail == obj.answers.recemail &&        list[i].answers.recemail == obj.answers.youremail      ) {        res.push([ obj.answers.youremail, obj.answers.recemail ]);      }    }  });  console.log(res);


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -