[英]Javascript and MongoDB - write to file
I'm using mongoDB on an ubuntu server. 我在ubuntu服务器上使用mongoDB。 However I'm using a javascript to store data and do some map/reduce.
但是我使用javascript来存储数据并做一些map / reduce。 I would like to measure these operations and write the results into a file.
我想测量这些操作并将结果写入文件。 Somehow I fail to open a file and write into it.. I tried the following:
不知何故,我无法打开文件并写入其中..我尝试了以下内容:
f = new File("myfile.txt");
if(f.open("w") == true)
{
f.write("test");
f.Close();
}
简单回答:你不能用Javascript写文件。
最好使用println写入控制台并将输出重定向到文件,将javascript文件作为参数传递给mongo。
mongo someprocess.js > outpout
The file
object within spidermonkey (the JS engine MongoDB uses, and coincidently the console) has been made obsolete: https://developer.mozilla.org/en-US/docs/SpiderMonkey/File_object . spidermonkey中的
file
对象(MongoDB使用的JS引擎,以及巧合的控制台)已经过时了: https : //developer.mozilla.org/en-US/docs/SpiderMonkey/File_object 。 Not only that but it wasn't standard to spidermonkey anyway so that was a long shot. 不仅如此,但无论如何它都不是蜘蛛侠的标准,所以这是一个长镜头。
As @gkamal states, the best way is to pipe the output of the MongoDB console like so: 正如@gkamal所说,最好的方法是管道MongoDB控制台的输出,如下所示:
mongo someprocess.js > outpout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.