如何在MongoDB中调试存储的javascript函数? [英] How can you debug stored javascript functions in MongoDB?

查看:55
本文介绍了如何在MongoDB中调试存储的javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将一些工作流逻辑从C#代码移动到MongoDB中存储的JS(例如,用户发送一条消息,要在不同的集合中创建一堆或记录,现在我在C#中进行此操作) ),但我担心如果事情无法正常进行,我是否能够调试该JS代码.

I'm thinking of moving some workflow logic from C# code to stored JS in MongoDB (for example, wen a user sends a message, a bunch or records is to be created in different collections, which right now I do in C#), but I'm concerned whether I would be able to debug that JS code if things don't work correctly.

推荐答案

没有特定的功能.您可以做的一件事是在mongo shell中运行某些代码,该代码可以执行与服务器完全相同的javascript.该外壳程序没有调试器,但借助其交互式提示,尝试操作,检查变量等会容易得多.

There isn't a particular facility for that. One thing you could do is run some of that code in the mongo shell, which can execute exactly the same javascript as the server. The shell doesn't have a debugger but with its interactive prompt it would be much easier to try things, inspect variables, etc.

我个人并不一定建议将代码移入服务器.请注意,可以连续发送多个写入操作(例如插入),然后在发送多个请求进行单个确认之后发送.因此,即使存在一些非平凡的网络延迟,这种情况也不一定会变慢.

Personally I would not necessarily recommend moving code into the server. Note it is possible to send several write operations (such as inserts) in a row and then after sending several ask for a single acknowledgement. Thus that scenario is not necessarily slow even if there is some nontrivial network latency.

或者,您可以在与mongod进程相同的服务器上运行C#代码,从而在请求周转方面获得极低的延迟.一种方法是制作一个用C#编写并封装上面建议的逻辑的Web服务器.

Alternatively you could run C# code on the same server as the mongod process and thereby get extremely low latency on turnarounds of requests. One way to do that would be to make a web server that is written in C# and encapsulates the logic suggested above.

这篇关于如何在MongoDB中调试存储的javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆