Mongo Shell – 控制台/debugging日志

可能是一个愚蠢的问题。 试用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函数时,如何输出到控制台。 我打算一些pipe理员/填充脚本,我想输出一些精美的信息。

我已经试过console.log,debug.log,logging明显的..

我find了答案,它只是print

 print("sweetnesss"); 

我通常在与shell进行交互时使用脚本,因此我编写了一个基本的Logging对象,将其“加载(脚本)”到shell中,然后使用Logging对象调用日志级别(debugging,信息,警告,错误)。 Logger对象使用“print”和“printjson”作为核心。 另外,它包含一个基本的sprintf,填充,logging格式化等。如果你打算用mongodb做足够多的脚本工作,我推荐这个路线。 debuggingmongodb脚本感觉就像回到编程和debugging打印语句的介绍。 可configuration的日志logging使这个更好一点,但我真的很想念能够通过代码。