github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/processors/mongodb.md (about) 1 --- 2 title: mongodb 3 type: processor 4 status: experimental 5 categories: ["Integration"] 6 --- 7 8 <!-- 9 THIS FILE IS AUTOGENERATED! 10 11 To make changes please edit the contents of: 12 lib/processor/mongodb.go 13 --> 14 15 import Tabs from '@theme/Tabs'; 16 import TabItem from '@theme/TabItem'; 17 18 :::caution EXPERIMENTAL 19 This component is experimental and therefore subject to change or removal outside of major version releases. 20 ::: 21 Performs operations against MongoDB for each message, allowing you to store or retrieve data within message payloads. 22 23 Introduced in version 3.43.0. 24 25 26 <Tabs defaultValue="common" values={[ 27 { label: 'Common', value: 'common', }, 28 { label: 'Advanced', value: 'advanced', }, 29 ]}> 30 31 <TabItem value="common"> 32 33 ```yaml 34 # Common config fields, showing default values 35 label: "" 36 mongodb: 37 url: "" 38 database: "" 39 username: "" 40 password: "" 41 operation: insert-one 42 collection: "" 43 write_concern: 44 w: "" 45 j: false 46 w_timeout: "" 47 document_map: "" 48 filter_map: "" 49 hint_map: "" 50 upsert: false 51 ``` 52 53 </TabItem> 54 <TabItem value="advanced"> 55 56 ```yaml 57 # All config fields, showing default values 58 label: "" 59 mongodb: 60 url: "" 61 database: "" 62 username: "" 63 password: "" 64 operation: insert-one 65 collection: "" 66 write_concern: 67 w: "" 68 j: false 69 w_timeout: "" 70 document_map: "" 71 filter_map: "" 72 hint_map: "" 73 upsert: false 74 json_marshal_mode: canonical 75 parts: [] 76 max_retries: 3 77 backoff: 78 initial_interval: 1s 79 max_interval: 5s 80 max_elapsed_time: 30s 81 ``` 82 83 </TabItem> 84 </Tabs> 85 86 ## Fields 87 88 ### `url` 89 90 The URL of the target MongoDB DB. 91 92 93 Type: `string` 94 Default: `""` 95 96 ```yaml 97 # Examples 98 99 url: mongodb://localhost:27017 100 ``` 101 102 ### `database` 103 104 The name of the target MongoDB DB. 105 106 107 Type: `string` 108 Default: `""` 109 110 ### `username` 111 112 The username to connect to the database. 113 114 115 Type: `string` 116 Default: `""` 117 118 ### `password` 119 120 The password to connect to the database. 121 122 123 Type: `string` 124 Default: `""` 125 126 ### `operation` 127 128 The mongodb operation to perform. 129 130 131 Type: `string` 132 Default: `"insert-one"` 133 Options: `insert-one`, `delete-one`, `delete-many`, `replace-one`, `update-one`, `find-one`. 134 135 ### `collection` 136 137 The name of the target collection in the MongoDB DB. 138 This field supports [interpolation functions](/docs/configuration/interpolation#bloblang-queries). 139 140 141 Type: `string` 142 Default: `""` 143 144 ### `write_concern` 145 146 The write_concern settings for the mongo connection. 147 148 149 Type: `object` 150 151 ### `write_concern.w` 152 153 W requests acknowledgement that write operations propagate to the specified number of mongodb instances. 154 155 156 Type: `string` 157 Default: `""` 158 159 ### `write_concern.j` 160 161 J requests acknowledgement from MongoDB that write operations are written to the journal. 162 163 164 Type: `bool` 165 Default: `false` 166 167 ### `write_concern.w_timeout` 168 169 The write concern timeout. 170 171 172 Type: `string` 173 Default: `""` 174 175 ### `document_map` 176 177 A bloblang map representing the records in the mongo db. Used to generate the document for mongodb by mapping the fields in the message to the mongodb fields. The document map is required for the operations insert-one, replace-one and update-one. 178 179 180 Type: `string` 181 Default: `""` 182 183 ```yaml 184 # Examples 185 186 document_map: |- 187 root.a = this.foo 188 root.b = this.bar 189 ``` 190 191 ### `filter_map` 192 193 A bloblang map representing the filter for the mongo db command. The filter map is required for all operations except insert-one. It is used to find the document(s) for the operation. For example in a delete-one case, the filter map should have the fields required to locate the document to delete. 194 195 196 Type: `string` 197 Default: `""` 198 199 ```yaml 200 # Examples 201 202 filter_map: |- 203 root.a = this.foo 204 root.b = this.bar 205 ``` 206 207 ### `hint_map` 208 209 A bloblang map representing the hint for the mongo db command. This map is optional and is used with all operations except insert-one. It is used to improve performance of finding the documents in the mongodb. 210 211 212 Type: `string` 213 Default: `""` 214 215 ```yaml 216 # Examples 217 218 hint_map: |- 219 root.a = this.foo 220 root.b = this.bar 221 ``` 222 223 ### `upsert` 224 225 The upsert setting is optional and only applies for update-one and replace-one operations. If the filter specified in filter_map matches,the document is updated or replaced accordingly, otherwise it is created. 226 227 228 Type: `bool` 229 Default: `false` 230 Requires version 3.60.0 or newer 231 232 ### `json_marshal_mode` 233 234 The json_marshal_mode setting is optional and controls the format of the output message. 235 236 237 Type: `string` 238 Default: `"canonical"` 239 Requires version 3.60.0 or newer 240 241 | Option | Summary | 242 |---|---| 243 | `canonical` | A string format that emphasizes type preservation at the expense of readability and interoperability. That is, conversion from canonical to BSON will generally preserve type information except in certain specific cases. | 244 | `relaxed` | A string format that emphasizes readability and interoperability at the expense of type preservation.That is, conversion from relaxed format to BSON can lose type information. | 245 246 247 ### `parts` 248 249 An optional array of message indexes of a batch that the processor should apply to. 250 If left empty all messages are processed. This field is only applicable when 251 batching messages [at the input level](/docs/configuration/batching). 252 253 Indexes can be negative, and if so the part will be selected from the end 254 counting backwards starting from -1. 255 256 257 Type: `array` 258 Default: `[]` 259 260 ### `max_retries` 261 262 The maximum number of retries before giving up on the request. If set to zero there is no discrete limit. 263 264 265 Type: `int` 266 Default: `3` 267 268 ### `backoff` 269 270 Control time intervals between retry attempts. 271 272 273 Type: `object` 274 275 ### `backoff.initial_interval` 276 277 The initial period to wait between retry attempts. 278 279 280 Type: `string` 281 Default: `"1s"` 282 283 ### `backoff.max_interval` 284 285 The maximum period to wait between retry attempts. 286 287 288 Type: `string` 289 Default: `"5s"` 290 291 ### `backoff.max_elapsed_time` 292 293 The maximum period to wait before retry attempts are abandoned. If zero then no limit is used. 294 295 296 Type: `string` 297 Default: `"30s"` 298 299