How can you debug saved javascript functions in MongoDB?

I am going to move some workflow logic from C # code to saved JS in MongoDB (for example, if the user sends a message, the bundle or records must be created in different collections that I am doing in C # right now), but I'm worried if I can I am debugging this js code if something is not working correctly.

+6
source share
2 answers

There is no specific object for this. One thing you could do is run part of this code in the mongo shell, which can execute exactly the same javascript as the server. There is no debugger in the shell, but with its interactive prompt it would be much easier to try things, check variables, etc.

Personally, I would not recommend moving the code to the server. Please note that you can send several write operations (for example, inserts) on one line, and then after sending to several, request one confirmation. Thus, this scenario is not necessarily slow, even if there is nontrivial latency of the network.

Alternatively, you can run C # code on the same server as the mongod process, and thus get an extremely low latency when processing requests. One way to do this is to make a web server written in C # and encapsulate the logic suggested above.

+1
source

I think you can write some debugging information in a separate collection and see how things are going, but it seems to me that actual debugging is impossible.

+1
source

Source: https://habr.com/ru/post/891234/


All Articles