<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[I want to update database inside a for loop.But before my database update for loop ends. (#node js, #mongoose)]]></title><description><![CDATA[<p dir="auto">var patientObj = JSON.parse(JSON.stringify(patients));</p>
<p dir="auto">for (var i = 0; i &lt; patientObj.length; i++) {<br />
var patientIds = "00" + (i + 1);<br />
var patientNewIdObj = { barCodeId: patientIds}<br />
var currentPatientId = patientObj[i]._id;</p>
<pre><code>modelPatient.findOneAndUpdate({ _id: currentPatientId }, patientNewIdObj, 
{ new: true, safe: true }).exec(function (err, patientRet) {
    if (err) {
        callBack(callBackResponse.callbackWithDefaultError(err));
    }
    else if (patientRet == null || patientRet == undefined) {
        callBack(callBackResponse.callbackWithfalseMessage('Invalid 
        patient ID'));
    } else {
        callBack(callBackResponse.callbackWithData(patientRet));
    }
});
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://lankadevelopers.lk/topic/271/i-want-to-update-database-inside-a-for-loop-but-before-my-database-update-for-loop-ends-node-js-mongoose</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 03:11:48 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/271.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Jun 2019 09:00:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to I want to update database inside a for loop.But before my database update for loop ends. (#node js, #mongoose) on Mon, 17 Jun 2019 06:39:16 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://javascript.info/async-await" target="_blank" rel="noopener noreferrer nofollow ugc">https://javascript.info/async-await</a></p>
]]></description><link>https://lankadevelopers.lk/post/1707</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1707</guid><dc:creator><![CDATA[ijseGovindu]]></dc:creator><pubDate>Mon, 17 Jun 2019 06:39:16 GMT</pubDate></item><item><title><![CDATA[Reply to I want to update database inside a for loop.But before my database update for loop ends. (#node js, #mongoose) on Sun, 16 Jun 2019 13:54:53 GMT]]></title><description><![CDATA[<p dir="auto">check this link<br />
<a href="https://lavrton.com/javascript-loops-how-to-handle-async-await-6252dd3c795/" target="_blank" rel="noopener noreferrer nofollow ugc">https://lavrton.com/javascript-loops-how-to-handle-async-await-6252dd3c795/</a></p>
]]></description><link>https://lankadevelopers.lk/post/1706</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1706</guid><dc:creator><![CDATA[Danushka96]]></dc:creator><pubDate>Sun, 16 Jun 2019 13:54:53 GMT</pubDate></item><item><title><![CDATA[Reply to I want to update database inside a for loop.But before my database update for loop ends. (#node js, #mongoose) on Sun, 16 Jun 2019 06:49:44 GMT]]></title><description><![CDATA[<p dir="auto"><strong>how to use await function for this code.</strong></p>
<pre><code>var patientObj = JSON.parse(JSON.stringify(patients));

for (var i = 0; i &lt; patientObj.length; i++) {
var patientIds = "00" + (i + 1);
var patientNewIdObj = { barCodeId: patientIds}
var currentPatientId = patientObj[i]._id;

modelPatient.findOneAndUpdate({ _id: currentPatientId }, patientNewIdObj, 
{ new: true, safe: true }).exec(function (err, patientRet) {
    if (err) {
        callBack(callBackResponse.callbackWithDefaultError(err));
    }
    else if (patientRet == null || patientRet == undefined) {
        callBack(callBackResponse.callbackWithfalseMessage('Invalid 
        patient ID'));
    } else {
        callBack(callBackResponse.callbackWithData(patientRet));
    }
});
}
</code></pre>
]]></description><link>https://lankadevelopers.lk/post/1705</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1705</guid><dc:creator><![CDATA[kasun viduranga]]></dc:creator><pubDate>Sun, 16 Jun 2019 06:49:44 GMT</pubDate></item><item><title><![CDATA[Reply to I want to update database inside a for loop.But before my database update for loop ends. (#node js, #mongoose) on Sat, 15 Jun 2019 19:05:49 GMT]]></title><description><![CDATA[<p dir="auto">Maybe that's because of the loop runs without waiting for your delete process finished. Try an await function.</p>
]]></description><link>https://lankadevelopers.lk/post/1703</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1703</guid><dc:creator><![CDATA[Danushka96]]></dc:creator><pubDate>Sat, 15 Jun 2019 19:05:49 GMT</pubDate></item><item><title><![CDATA[Reply to I want to update database inside a for loop.But before my database update for loop ends. (#node js, #mongoose) on Fri, 14 Jun 2019 16:37:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/27">@root</a>  FYI</p>
]]></description><link>https://lankadevelopers.lk/post/1700</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1700</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Fri, 14 Jun 2019 16:37:36 GMT</pubDate></item></channel></rss>