Mongo Shell - 控制台/调试日志

时间:2010-02-25 14:04:20

标签: mongodb

可能是一个愚蠢的问题。尝试使用Mongo shell。

我想做类似的事情:

matt@linuxvm:~/mongodb-linux-i686-1.2.3/bin$ ./mongo
MongoDB shell version: 1.2.3
url: test
connecting to: test
Thu Feb 25 20:57:47 connection accepted from 127.0.0.1:37987 #3
type "help" for help
> function test() { debug.log("hello") }
> test()
Thu Feb 25 20:58:06 JS Error: ReferenceError: debug is not defined (shell):0

换句话说,在从Mongo shell中评估JS函数时,如何输出到控制台。我想要一些管理/填充脚本,我想输出一些精确的信息。

我已经尝试过console.log,debug.log,记录明显的那些..

2 个答案:

答案 0 :(得分:240)

我找到了答案,只是print

print("sweetnesss");

答案 1 :(得分:2)

我通常在与shell交互时使用脚本,因此我编写了一个基本的Logging对象,我将其“加载(脚本)”到shell中,然后使用Logging对象调用日志记录级别(debug,info,warn,error )。 Logger对象在其核心使用'print'和'printjson'。此外,它包含一个基本的sprintf,填充,记录格式等。如果你要使用mongodb做任何大量的脚本工作,我推荐这条路线。调试mongodb脚本感觉就像回到使用print语句编程和调试的介绍。可配置的日志记录使这更好一点,但我真的很想能够逐步完成代码。

相关问题