I am fighting for some days now with a "simple" query to gather information from a mongo DB:
var obj = {};
obj.file = db.collection(dbcollectionname);
const domain = '';
const rname = 'DeviceNamce-22';
obj.file.find({type: 'node', domain: '', rname: rname}).sort({ lastbootuptime: -1 }).limit(1).toArray(function (err, docs) { err, console.log(docs); });
The query works in the console, but keeps the command opened. You might see it because of the cursor symbol:
I would expect that I get the console sign ">" back so that I can type the next command, but I have to push it manually. I also tried findeOne and then, but all behave the same. I also added after the console.log a return, but nothing changes.
Can someone help me what I might be missing? The output is fine, saying the result is correct, it just doesn't release it.
The real function I later want to use is:
obj.GetNodeByComputerName = function (domain, rname, func) { obj.file.find({ type: 'node', domain: domain, rname: rname }).sort({ lastbootuptime: -1 }).limit(1).toArray(function (err, docs) { func(err, performTypedRecordDecrypt(docs)); }); };
but this just gets ignored. I think it is because the query never really terminates like when I do it manually in nodeJS
Edit2:
I am even more confused. I set up a second system with the same query and it works without an issue. The only difference, I added first the modification to my js files and then set up the mongo db which runs in a different container. But I also use podman on my first system, so thats the same.
Edit3: OK, the function worked fine all time. The problem was, when there is no return value, the inside function is not called which set not my boolean correctly. So the error was me