Example #1
0
 public IEnumerable<string> GetDatabaseNames()
 {
     Contract.Ensures(Contract.Result<IEnumerable<string>>() != null);
       var names = new List<string>();
       dynamic cmd = new Command("listDatabases", 1);
       dynamic result = GetDB("admin").ExecuteCommand(cmd);
       foreach (var db in result.databases)
       {
     names.Add(db.name as string);
       }
       return names;
 }
 public void RenameCollection(string oldName, string newName)
 {
     Contract.Requires(Collection.NameOk(newName));
       Contract.Requires(!newName.Contains('$'));
       var cmd = new Command("renameCollection", string.Format("{0}.{1}", Name, oldName))
     { { "to", string.Format("{0}.{1}", Name, newName) } };
       Admin.ExecuteCommand(cmd);
 }
 public string Eval(ScopedCode code, params string[] args)
 {
     var cmd = new Command("$eval", code) { { "args", args } };
       return ExecuteCommand(cmd)["retval"] as string;
 }
 public Doc ExecuteCommand(Command cmd)
 {
     Contract.Requires(cmd != null);
       return GetCollection("$cmd").FindOne(cmd);
 }
 private void Create(IDictionary<string, object> options)
 {
     if (options.ContainsKey("size"))
       {
     options["size"] = Convert.ToDouble(options["size"]);
       }
       var cmd = new Command("create", Name);
       foreach (var item in options)
       {
     cmd[item.Key] = item.Value;
       }
       Database.ExecuteCommand(cmd);
 }