Venom - Executor Mongo
Step to execute actions on a MongoDB database.
See also tests/mongo.yml for executable examples.
Note: most fields support MongoDB Extended JSON v2.
This means some special values (ObjectIds, ISODates, etc.) can be represented using the relaxed format.
Example:
{
"_id": {
"$oid": "5d505646cf6d4fe581014ab2"
}
}
Load fixtures
- type: mongo
uri: mongodb://localhost:27017
database: my-database
actions:
- type: loadFixtures
folder: fixtures/
This action will first drop all the collections in the database, and then load multiple collections at once from a folder.
The fixtures folder must contain one file per collection, and be named after the collection. For example, cards.yml
will create a cards
collection.
The items in the collections are declared as a YAML array. For example:
# fixtures/cards.yml
- suit: clubs
value: jack
- suit: clubs
value: queen
- suit: clubs
value: king
Insert documents
- 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
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: insert
file: fixtures/my-collection.jsonlist
fixtures/my-collection.jsonlist
:
{
"suit": "hearts",
"value": "queen"
}
{
"suit": "diamonds",
"value": "three"
}
Find documents
- 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
- 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
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: count
filter: |
{
"suit": "clubs"
}
Update documents
- 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
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: delete
filter: |
{
"suit": "circles"
}
Aggregate documents
- 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
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: createCollection
Drop a collection
- type: mongo
uri: mongodb://localhost:27017
database: my-database
collection: my-collection
actions:
- type: dropCollection