开发者

Write mongodb mapReduce result to a file

I have a collection in MongoDb where data in the collection has the following structure :

{userid = 1 (the id of the user), key1 = value1 , key2 = value2, .... }

I want to write mongodb mapreduce functions where i could put the userid in the map function and in the reduce function i need to write they ( key,value ) pairs in a开发者_运维知识库 csv (?) file such that they would be :

key1,key2, key3,...

value1,value2,value3,..

value1,value2,value3,..

value1,value2,value3,..

How can i do that with mongodb

Thanks


There is no "file output" option.

The MongoDB documentation has details on exporting data.

In particular, mongoexport allows for export by JSON or CSV which should be legible from other software.

If you want to significantly modify the data output, then you'll have to use a client library and cursor through the data while writing to a file.


You can not write data to a file directly. You have to implement such a functionality on the application level by reading the data from the collection and writing it to the filesystem in whatever format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜