I need a while to verify if a generated id alredy exists in the db, so i made this code:
let ssid;
while ( ssid == undefined ) {
let tempSId = assets.makeid(30);
MongoClient.connect(mongoUrl, function(err, db) {
if (err) message.guild.owner.user.send(assets.err(err));
var dbo = db.db(conf.mainDB.name);
var query = { sid: tempSId };
dbo.collection(conf.mainDB.tables[0]).find(query).toArray(function(err, result) {
if (err) message.guild.owner.user.send(assets.err(err));
if ( result[0] == undefined ) { ssid = tempSId; }
db.close();
});
});
}
where i search for objects in the db with the same id. But it gives me this error:
[Admin Tools] > Online!
(node:22154) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
<--- Last few GCs --->
[22154:0x49ca400] 44793 ms: Mark-sweep 2044.1 (2051.6) -> 2043.4 (2051.6) MB, 1441.8 / 0.8 ms (average mu = 0.048, current mu = 0.008) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x13cf019]
1: StubFrame [pc: 0x13d00b3]
Security context: 0x056c5c2c08d1 <JSObject>
2: /* anonymous */ [0x3939aff47e49] [/home/ezzer29/node-apps/admin-tools-discord/main.js:~28] [pc=0x26120c4a55dd](this=0x1c40355822c9 <JSGlobal Object>,0x3ce30b9001b9 <null>,0x3939aff47e89 <JSArray[0]>)
3: /* anonymous */(aka /* anonymous */) [0x3939aff47ea9] [/home/ezzer29/node-apps/admin-tools-discord/node_modules/mongod...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xa093f0 node::Abort() [node]
2: 0xa097fc node::OnFatalError(char const*, char const*) [node]
3: 0xb842ae v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xb84629 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xd30fe5 [node]
6: 0xd31676 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
7: 0xd3def5 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
8: 0xd3eda5 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9: 0xd4185c v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
10: 0xd0830b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
11: 0x1049f4e v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x13cf019 [node]
Aborted (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! admin-tools@1.0.0 start: `node main.js`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the admin-tools@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ezzer29/.npm/_logs/2020-09-13T13_48_17_874Z-debug.log
the query function works ffine on its own and so does the while but when i put them together it crashes.
Thanks!