Source code for saltext.mongodb.states.mongodb_database
"""Management of MongoDB Databases===============================:depends: - pymongo Python moduleOnly deletion is supported, creation doesn't make sense and can be done using:py:func:`mongodb_user.present <salt.states.mongodb_user.present>`."""# Define the module's virtual name__virtualname__="mongodb_database"def__virtual__():if"mongodb.db_exists"in__salt__:return__virtualname__return(False,"mongodb module could not be loaded")
[docs]defabsent(name,user=None,password=None,host=None,port=None,authdb=None):""" Ensure that the named database is absent. Note that creation doesn't make sense in MongoDB. name The name of the database to remove user The user to connect as (must be able to create the user) password The password of the user host The host to connect to port The port to connect to authdb The database in which to authenticate """ret={"name":name,"changes":{},"result":True,"comment":""}if__salt__["mongodb.db_exists"](name,user,password,host,port,authdb=authdb):if__opts__["test"]:ret["result"]=Noneret["comment"]=f"Database {name} is present and needs to be removed"returnretif__salt__["mongodb.db_remove"](name,user,password,host,port,authdb=authdb):ret["comment"]=f"Database {name} has been removed"ret["changes"][name]="Absent"returnretret["comment"]=f"Database {name} is not present"returnret