Skip to content

Commit

Permalink
feat: mongo executor (#601)
Browse files Browse the repository at this point in the history
* typos

Signed-off-by: Thibaut Rousseau <thibaut.rousseau.44@gmail.com>

* add mongo executor

Signed-off-by: Thibaut Rousseau <thibaut.rousseau.44@gmail.com>

* replace __len__ with ShouldHaveLength

Signed-off-by: Thibaut Rousseau <thibaut.rousseau.44@gmail.com>

* add mongo test stack

Signed-off-by: Thibaut Rousseau <thibaut@crew.work>

---------

Signed-off-by: Thibaut Rousseau <thibaut.rousseau.44@gmail.com>
Signed-off-by: Thibaut Rousseau <thibaut@crew.work>
  • Loading branch information
Thiht authored Feb 13, 2023
1 parent 80cff7a commit 4a8b0d6
Show file tree
Hide file tree
Showing 11 changed files with 793 additions and 12 deletions.
5 changes: 3 additions & 2 deletions executors/dbfixtures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

Step to load fixtures into **MySQL** and **PostgreSQL** databases.

It use the package `testfixtures/v3` under the hood: https://github.com/go-testfixtures/testfixtures
It uses the package `testfixtures/v3` under the hood: https://github.com/go-testfixtures/testfixtures
Please read its documentation for further details about the parameters of this executor, especially `folder` and `files`, and how you should write the fixtures.

## Input
In your yaml file, you declare tour step like this

In your yaml file, you declare your step like this

```yaml
- database mandatory [mysql/postgres/sqlite3]
Expand Down
199 changes: 199 additions & 0 deletions executors/mongo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# Venom - Executor Mongo

Step to execute actions on a MongoDB database.

## Input

See also [tests/mongo.yml](../../tests/mongo.yml) for executable examples.

Note: most fields support [MongoDB Extended JSON v2](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/).
This means some special values (ObjectIds, ISODates, etc.) can be represented using the relaxed format.

Example:

```json
{
"_id": {
"$oid": "5d505646cf6d4fe581014ab2"
}
}
```

### Insert documents

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: insert
documents:
- '{"suit": "hearts", "value": "queen"}'
- '{"suit": "diamonds", "value": "three"}'
```
### Insert documents from a file
```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: insert
file: fixtures/my-collection.jsonlist
```
`fixtures/my-collection.jsonlist`:

```json
{
"suit": "hearts",
"value": "queen"
}
{
"suit": "diamonds",
"value": "three"
}
```

### Find documents

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: find
filter: |
{
"suit": "clubs"
}
options: # optional
limit: 3
skip: 1
sort: '{"_id": -1}'
projection: '{"value": 1}'
```

### Find documents by ObjectID

See: [MongoDB Extended JSON - Type Representations](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/#type-representations)

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: find
filter: |
{
"_id": {
"$oid": "5d505646cf6d4fe581014ab2"
}
}
options: # optional
limit: 3
skip: 1
sort: '{"_id": -1}'
projection: '{"value": 1}'
```

### Count documents

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: count
filter: |
{
"suit": "clubs"
}
```

### Update documents

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: update
filter: |
{
"suit": {
"$in": ["clubs", "spades"]
}
}
update: |
{
"$set": {
"color": "black"
}
}
```

### Delete documents

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: delete
filter: |
{
"suit": "circles"
}
```

### Aggregate documents

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: aggregate
pipeline:
- |
{ "$match": {
"color": "black"
}}
- |
{ "$group": {
"_id": "$value",
"count": {"$sum": 1}
}}
```

### Create a collection

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: createCollection
```

### Drop a collection

```yaml
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: dropCollection
```
Loading

0 comments on commit 4a8b0d6

Please sign in to comment.