0

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: enter image description here

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

3
  • What exactly is the command you ran? If you wrapped it in something like console log, it is possible the REPL printed the prompt before the data was output to the screen. Commented Oct 10 at 16:24
  • @Joe, I updated the question. But actually thats the real command. Trying await helps me in the console, but not when I later run the code. Very confusing Commented Oct 10 at 17:10
  • See if this discussion helps: stackoverflow.com/questions/45118957/… Commented Oct 10 at 22:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.