Module to provide MongoDB functionality to Salt
This module uses PyMongo, and accepts configuration details as parameters as well as configuration settings:
mongodb.host: 'localhost'
mongodb.port: 27017
mongodb.user: ''
mongodb.password: ''
This data can also be passed into pillar. Options passed into opts will overwrite options passed into pillar.
New in version 3006.0.
Create a collection in the specified database.
The name of the collection to create.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.collection_create mycollection <user> <password> <host> <port> <database>
New in version 3006.0.
Drop a collection in the specified database.
The name of the collection to drop.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.collection_drop mycollection <user> <password> <host> <port> <database>
New in version 3006.0.
List the collections available in the specified database.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.collections_list mycollection <user> <password> <host> <port> <database>
Checks if a database exists in MongoDB
The name of the database to check for.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.db_exists <name> <user> <password> <host> <port>
List all MongoDB databases
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.db_list <user> <password> <host> <port>
Remove a MongoDB database
The name of the database to remove.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.db_remove <name> <user> <password> <host> <port>
Find an object or list of objects in a collection
The collection to find the objects in.
The query to use when locating objects in the collection.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.find mycollection '[{"foo": "FOO", "bar": "BAR"}]' <user> <password> <host> <port> <database>
Insert an object or list of objects into a collection
The objects to insert into the collection, should be provided as a list.
The collection to insert the objects into.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.insert '[{"foo": "FOO", "bar": "BAR"}, {"foo": "BAZ", "bar": "BAM"}]' mycollection <user> <password> <host> <port> <database>
Remove an object or list of objects from a collection
The collection to remove objects from based on the query.
Query to determine which objects to remove.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The database where the collection is.
The number of matches to remove from the collection.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.remove mycollection '[{"foo": "FOO", "bar": "BAR"}, {"foo": "BAZ", "bar": "BAM"}]' <user> <password> <host> <port> <database>
Update an object into a collection http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.update_one
New in version 2016.11.0.
The objects to update in the collection, should be provided as a list.
The collection to insert the objects into.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.update_one '{"_id": "my_minion"} {"bar": "BAR"}' mycollection <user> <password> <host> <port> <database>
Create a MongoDB user
The name of the user to create.
The password for the user that is being created.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use when checking if the user exists. Default is admin
.
The MongoDB database to use for authentication. Default is None.
The roles that should be associated with the user. Default is None.
CLI Example:
salt '*' mongodb.user_create <user_name> <user_password> <roles> <user> <password> <host> <port> <database>
Checks if a user exists in MongoDB
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use when checking if the user exists. Default is admin
.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.user_exists <name> <user> <password> <host> <port> <database>
Get single user from MongoDB
The name of the user to find.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use when looking for the user. Default is admin
.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.user_find <name> <user> <password> <host> <port> <database> <authdb>
Grant one or many roles to a MongoDB user
The user to grant the specified roles to.
The roles to grant to the specified user.
The database to great the roles against for the specified user.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Examples:
salt '*' mongodb.user_grant_roles johndoe '["readWrite"]' dbname admin adminpwd localhost 27017
salt '*' mongodb.user_grant_roles janedoe '[{"role": "readWrite", "db": "dbname" }, {"role": "read", "db": "otherdb"}]' dbname admin adminpwd localhost 27017
List users of a MongoDB database
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use when listing users. Default is admin
.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.user_list <user> <password> <host> <port> <database>
Remove a MongoDB user
The name of the user that should be removed.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.user_remove <name> <user> <password> <host> <port> <database>
Revoke one or many roles to a MongoDB user
The user to connect to MongoDB as. Default is None.
The roles to revoke from the specified user.
The database to revoke the roles from for the specified user.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Examples:
salt '*' mongodb.user_revoke_roles johndoe '["readWrite"]' dbname admin adminpwd localhost 27017
salt '*' mongodb.user_revoke_roles janedoe '[{"role": "readWrite", "db": "dbname" }, {"role": "read", "db": "otherdb"}]' dbname admin adminpwd localhost 27017
Checks if a user of a MongoDB database has specified roles
The name of the user to check for the specified roles.
The roles to check are associated with the specified user.
The database to check has the specified roles for the specified user.
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Examples:
salt '*' mongodb.user_roles_exists johndoe '["readWrite"]' dbname admin adminpwd localhost 27017
salt '*' mongodb.user_roles_exists johndoe '[{"role": "readWrite", "db": "dbname" }, {"role": "read", "db": "otherdb"}]' dbname admin adminpwd localhost 27017
Get MongoDB instance version
The user to connect to MongoDB as. Default is None.
The password to use to connect to MongoDB as. Default is None.
The host where MongoDB is running. Default is None.
The host where MongoDB is running. Default is None.
The MongoDB database to use for authentication. Default is None.
CLI Example:
salt '*' mongodb.version <user> <password> <host> <port> <database>