You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to find any existing issue and went through the documentation but didn't manage to figure out what is wrong.
In my case I am inserting elements in the database in the callback of the find function that is called in the loop. Here is the code snippet:
for( var i = 0; i < houses.addresses.length; i++ ) {
let house = {
address: addresses[i]
};
await db.houses.find( { address: house.address }, async function( err, docs ) {
if( docs.length != 0 ) {
return;
}
await db.houses.insert( house, function ( error, newDoc ) {
if( error ) {
logger.error('Cant save the document: ' + JSON.stringify( doc ) + '. Caused by: ' + error );
}
});
So I am trying to find an entry, if entry doesn't exist I insert the entry. But for some reason I end up inserting many entries:
I was trying to find any existing issue and went through the documentation but didn't manage to figure out what is wrong.
In my case I am inserting elements in the database in the callback of the find function that is called in the loop. Here is the code snippet:
So I am trying to find an entry, if entry doesn't exist I insert the entry. But for some reason I end up inserting many entries:
{"address":"Vaartsestraat 0 ong","_id":"x5BtMrYmkiv2tOhy"}
{"address":"Vaartsestraat 0 ong","_id":"hms08wtX7yAEFpX3"}
{"address":"Vaartsestraat 0 ong","_id":"OjW99USIFU3adzoo"}
.....
Any idea why this might be happening?
The text was updated successfully, but these errors were encountered: