Mongodb
MongoDB is a cross-platform document-oriented database. This plugin provide a bridge for MongoDB databases.
Usage
In this example, we will setup the plugin to be used in the SMTP SMTP Receiver service. First, create a connection to the MongoDB database.
// /etc/vsmtp/smtp-receiver/services/db.rhai
// Import the plugin stored in the `plugins` directory.
import "plugins/libvsmtp_plugin_mongodb" as mongodb;
export const bridge = mongodb::connect("mongodb://admin:pass@localhost:27017");
Then query or mutate the database in your rules.
import "services/db" as db;
fn on_connect(ctx) {
ctx.run([
action "find a document in my collection" || {
let database = db::bridge.database("my_database");
let collection = database.collection("greylist");
collection.insert_many([
#{
"email": "john.doe@example.com",
"name": "John"
},
#{
"email": "jenny.doe@example.com"
"name": "Jenny"
}
]);
let user = collection.find_one(#{
"name": "John"
});
log("info", `the email is: ${user.email}`);
}
]);
}