---
title: "mongoDB 导出数据为csv格式"
author: "dikar"
date: "2011-05-05T15:01:26Z"
tags: ["C", "C#", "C++", "MongoDB", "json"]
categories: ["编程语言"]
slug: "mongodb-csv"
draft: false
lastmod: "2011-05-05T15:01:26Z"
id: 1030275
url: "https://dikar.iteye.com/blog/1030275"
---

mongoDB提供了 将数据导出为 json 或者CSV格式的文件的功能

 

具体见  http://www.mongodb.org/display/DOCS/Import+Export+Tools

 

其中需要注意的是：

If you want to output CSV, you have to specify the fields in the order you want them.

 

一个例子如下：

 

```
mongoexport -d dba22 -c foo -f x,y,a,b,c --csv -o ./result.csv
```

 -d  标示 数据库

 -c   标示  数据表

 -f   需要提取的field用逗号分隔

 -o  输出路径