# databaseMigrateExport

> 本接口应在服务器端调用，详细说明参见[服务端API](/miniprogram/dev/server/getting_started/api_signature.md)。

数据库导出

### 请求地址
```
POST https://api.weixin.qq.com/tcb/databasemigrateexport?access_token=ACCESS_TOKEN
```

### 请求参数

| 属性 | 类型 | 默认值 | 必填 | 说明 |
| ---- | ---- | ------ | -------- | ---- |
| access_token / cloudbase_access_token | string |  | 是 | [接口调用凭证](/minigame/dev/wxcloud/reference-http-api/functions/invokeCloudFunction) |
| env | string |  | 是 | 云环境ID |
| file_path | string |  | 是 | 导出文件路径（文件会导出到公共的云存储中，可使用[获取下载链接](/minigame/dev/wxcloud/reference-http-api/storage/batchDownloadFile) API 获取下载链接） |
| file_type | number |  | 是 | 导出文件类型，文件格式参考[数据库导入指引](/minigame/dev/wxcloud/guide/database/import)中的*文件格式*部分 |
| query | string |  | 是 | 导出条件 |

**file_type 的合法值**

| 值 | 说明 | 最低版本 |
| -- | ---- | ---- |
| 1 | JSON |  |
| 2 | CSV |  |

### 返回值

### Object

返回的 JSON 数据包

| 属性 | 类型 | 说明 |
| ---- | ---- | ---- |
| errcode  | number | 错误码 |
| errmsg  | string | 错误信息 |
| job_id  | number | 导出任务ID，使用[数据库迁移进度查询](databaseMigrateQueryInfo) API 查询导出结果，获取文件下载链接。 |

**errcode 的合法值**

| 值 | 说明 | 最低版本 |
| -- | ---- | ---- |
| 0 | 请求成功 |  |
| -1 | 系统错误 |  |
| -1000 | 系统错误 |  |
| 40014 | AccessToken 不合法 |  |
| 40097 | 请求参数错误 |  |
| 40101 | 缺少必填参数 |  |
| 41001 | 缺少AccessToken |  |
| 42001 | AccessToken过期 |  |
| 43002 | HTTP METHOD 错误 |  |
| 44002 | POST BODY 为空 |  |
| 47001 | POST BODY 格式错误 |  |
| 85088 | 该APP未开通云开发 |  |
| 其他错误码 | [云开发错误码](/minigame/dev/wxcloud/reference/errcode) |  |

### 请求数据示例

```json
{
    "env":"test2-4a89da",
    "file_path":"test_export",
    "file_type":1,
    "query":"const Point = db.Geo.Point;db.collection(\'geo\').where({name: \'x\',age: _.gt(10).and(_.lt(20)),loc: new Point(113,23),array: [1,2]}).limit(10).skip(1).orderBy(\'age\',\'asc\').orderBy(\'name\', \'desc\').field({ name: true }).get()"
}
```

### 返回数据示例

```json
{
    "errcode": 0,
    "errmsg": "ok",
    "job_id": 100074947
}
```

### 导出条件说明

查询语句语法与[数据库 API](/minigame/dev/wxcloud/reference-http-api/database/)相同
