未验证 提交 7b2398ca 编写于 作者: A Avi Aryan

Add transforms to docs

上级 b447d51f
......@@ -210,13 +210,13 @@ Each adaptor has its own README page with details on configuration and capabilit
Each native function can be used as part of a `Transform` step in the pipeline.
* [goja](./wiki/goja)
* [omit](./wiki/omit)
* [otto](./wiki/otto)
* [pick](./wiki/pick)
* [pretty](./wiki/pretty)
* [rename](./wiki/rename)
* [skip](./wiki/skip)
* [goja](docs/transforms/goja.md)
* [omit](docs/transforms/omit.md)
* [otto](docs/transforms/otto.md)
* [pick](docs/transforms/pick.md)
* [pretty](docs/transforms/pretty.md)
* [rename](docs/transforms/rename.md)
* [skip](docs/transforms/skip.md)
#### Commands
......
# goja function
`goja()` creates a JavaScript VM that receives and sends data through the defined javascript function for processing. The parameter passed to the function has been converted from a go map[string]interface{} to a JS object of the following form:
```JSON
{
"ns":"message.namespace",
"ts":12345, // time represented in milliseconds since epoch
"op":"insert",
"data": {
"id": "abcdef",
"name": "hello world"
}
}
```
***NOTE*** when working with data from MongoDB, the _id field will be represented in the following fashion:
```JSON
{
"ns":"message.namespace",
"ts":12345, // time represented in milliseconds since epoch
"op":"insert",
"data": {
"_id": {
"$oid": "54a4420502a14b9641000001"
},
"name": "hello world"
}
}
```
### configuration
```javascript
goja({"filename": "/path/to/transform.js"})
// js() is aliased to goja
// js({"filename": "/path/to/transform.js"})
```
### example
message in
```JSON
{
"_id": 0,
"name": "abc",
"type": "function"
}
```
config
```javascript
goja({"filename":"transform.js"})
```
transform function (i.e. `transform.js`)
```javascript
function transform(doc) {
doc["data"]["name_type"] = doc["data"]["name"] + " " + doc["data"]["type"];
return doc
}
```
message out
```JSON
{
"_id": 0,
"name": "abc",
"type": "function",
"name_type": "abc function"
}
```
\ No newline at end of file
# omit function
`omit()` will remove any fields specified from the message and then send down the pipeline. It currently only works for top level fields (i.e. `address.street` would not work).
### configuration
```javascript
omit({"fields": ["name"]})
```
### example
message in
```JSON
{
"_id": 0,
"name": "abc",
"type": "function"
}
```
config
```javascript
omit({"fields":["type"]})
```
message out
```JSON
{
"_id": 0,
"name": "abc"
}
```
\ No newline at end of file
# otto function
`otto()` creates a JavaScript VM that receives and sends data through the defined javascript function for processing. The parameter passed to the function has been converted from a go map[string]interface{} to a JS object of the following form:
```JSON
{
"ns":"message.namespace",
"ts":12345, // time represented in milliseconds since epoch
"op":"insert",
"data": {
"id": "abcdef",
"name": "hello world"
}
}
```
***NOTE*** when working with data from MongoDB, the _id field will be represented in the following fashion:
```JSON
{
"ns":"message.namespace",
"ts":12345, // time represented in milliseconds since epoch
"op":"insert",
"data": {
"_id": {
"$oid": "54a4420502a14b9641000001"
},
"name": "hello world"
}
}
```
### configuration
```javascript
otto({"filename": "/path/to/transform.js"})
// transform() is also available for backwards compatibility reasons but may be removed in future versions
// transform({"filename": "/path/to/transform.js"})
```
### example
message in
```JSON
{
"_id": 0,
"name": "abc",
"type": "function"
}
```
config
```javascript
otto({"filename":"transform.js"})
```
transform function (i.e. `transform.js`)
```javascript
module.exports=function(doc) {
doc["data"]["name_type"] = doc["data"]["name"] + " " + doc["data"]["type"];
return doc
}
```
message out
```JSON
{
"_id": 0,
"name": "abc",
"type": "function",
"name_type": "abc function"
}
```
\ No newline at end of file
# pick function
`pick()` will only include the specified fields from the message when sending down the pipeline. It currently only works for top level fields (i.e. `address.street` would not work).
### configuration
```javascript
pick({"fields": ["name"]})
```
### example
message in
```JSON
{
"_id": 0,
"name": "abc",
"type": "function"
}
```
config
```javascript
pick({"fields":["_id", "name"]})
```
message out
```JSON
{
"_id": 0,
"name": "abc"
}
```
\ No newline at end of file
# pretty function
`pretty()` will marshal the data to JSON and then log it at the `INFO` level. The default indention setting is `2` spaces and if set to `0`, it will print on a single line.
### configuration
```javascript
pretty({"spaces": 2})
```
### example
message in
```JSON
{
"_id": 0,
"name": "abc",
"type": "function"
}
```
config
```javascript
pretty({"spaces":0})
```
log line
```shell
INFO[0000]
{"_id":0,"name":"abc","type":"function"}
```
config
```javascript
pretty({"spaces":2})
```
log line
```shell
INFO[0000]
{
"_id":0,
"name":"abc",
"type":"function"
}
```
\ No newline at end of file
# rename function
`rename()` will update the replace existing key names with new ones based on the provided configuration. It currently only works for top level fields (i.e. `address.street` would not work).
### configuration
```javascript
rename({"field_map": {"test":"renamed"}})
```
### example
message in
```JSON
{
"_id": 0,
"name": "abc",
"type": "function",
"count": 10
}
```
config
```javascript
rename({"field_map": {"count":"total"}})
```
message out
```JSON
{
"_id": 0,
"name": "abc",
"type": "function",
"total": 10
}
```
\ No newline at end of file
# skip function
`skip()` will evalute the data based on the criteria configured and determine whether the message should continue down the pipeline or be skipped. When evaluating the data, `true` will result in the message being sent down the pipeline and `false` will result in the message being skipped. Take a look at the [tests](skipper_test.go) for all currently supported configurations. It currently only works for top level fields (i.e. `address.street` would not work).
### configuration
```javascript
skip({"field": "test", "operator": "==", "match": 10})
```
### example
message in
```JSON
{
"_id": 0,
"name": "abc",
"type": "function",
"count": 10
}
```
config
```javascript
skip({"field": "count", "operator": "==", "match": 10})
```
message out
```JSON
{
"_id": 0,
"name": "abc",
"type": "function",
"count": 10
}
```
config
```javascript
skip({"field": "count", "operator": ">", "match": 20})
```
message would be skipped
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册