0

I try to change an array of user in my mongodb from another collection. this is the code:

phrases.find({albumID: tileid}).toArray(function(err, results) {
    if (results.length > 0) {
        for(var j = 0; j < results.length; j++)
        {
            for(var z = 0; z < o.Phrases.length; z++)
            {
                if(o.Phrases[z].id == results[j]._id)
                {
                    o.Phrases.splice(z,1);
                    break;
                }
            }
        }
    }
});
console.log(o.Phrases);
. 
. 
. 
 after update the collection

When I do logs, I don't see the change being made. If I do the logs in toArray blocks, I see the changes. I read alot, And dont found solution only that toArray is async function but not how to change it or to use it. Maybe there is another way to change the collection to the array. thanks for helping.

Dor Swisa
  • 43
  • 1
  • 7
  • What is `Phrases` & `o.Phrases` ? – whoami - fakeFaceTrueSoul Dec 31 '19 at 01:13
  • Try adding a console log inside the z loop to output the value and type of both `o.Phrases[z].id` and `results[j]._id`. My suspicion is they never actually match, possibly because of a type or string formatting issue. – Joe Dec 31 '19 at 01:21
  • Sry i dont say that - o.Phrases is array in all user that signup to the site and i want to change the array. pharses is all the phrasas in the mongodb data base. – Dor Swisa Dec 31 '19 at 09:03
  • @Joe i check this its work he return true when they equal. – Dor Swisa Dec 31 '19 at 09:07

0 Answers0