Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (62 sloc) 2.39 KB
using System;
namespace MongoDB.Driver
/// <summary>
/// Administration of metadata for a database.
/// </summary>
public class DatabaseMetaData
private Connection connection;
private string name;
private Database db;
public DatabaseMetaData(string name, Connection conn){
this.connection = conn; = name;
this.db = new Database(conn, name);
public Collection CreateCollection(String name){
return this.CreateCollection(name,null);
public Collection CreateCollection(String name, Document options){
Document cmd = new Document();
cmd.Append("create", name).Update(options);
return new Collection(name, connection,;
public Boolean DropCollection(Collection col){
return this.DropCollection(col.Name);
public Boolean DropCollection(String name){
Document result = db.SendCommand(new Document().Append("drop",name));
return result.Contains("ok") && ((double)result["ok"] == 1);
public Boolean DropDatabase(){
throw new NotImplementedException();
public void AddUser(string username, string password){
Collection users = db["system.users"];
string pwd = Database.Hash(username + ":mongo:" + password);
Document user = new Document().Append("user", username).Append("pwd", pwd);
if (FindUser(username) != null){
throw new MongoException("A user with the name " + username + " already exists in this database.", null);
public void RemoveUser(string username){
Collection users = db["system.users"];
users.Delete(new Document().Append("user", username));
public Cursor ListUsers(){
Collection users = db["system.users"];
return users.FindAll();
public Document FindUser(string username){
return FindUser(new Document().Append("user",username));
public Document FindUser(Document spec){
return db["system.users"].FindOne(spec);