protected override void Execute(CodeActivityContext context) { var database_name = DB_Name.Get(context); var coll_name = Collection_Name.Get(context); var database_ip = DB_Server_IP.Get(context); //Connects to the Server MongoClient mongoclient = new MongoClient(database_ip); //List of all the Databases //Connects to the Existing Database if (DB_Delete_Flag.ToString() == "No") { var db_list = mongoclient.ListDatabaseNames().ToList(); if (db_list.Contains(database_name)) { MongoDatabaseBase myDB = (MongoDatabaseBase)mongoclient.GetDatabase(database_name); var coll_list = myDB.ListCollectionNames().ToList(); if (coll_list.Contains(coll_name)) { myDB.DropCollection(coll_name); } else { Console.WriteLine("Collection does not exsist"); } } else { Console.WriteLine("DB does not exsist"); } } else if (DB_Delete_Flag.ToString() == "Yes") { mongoclient.DropDatabase(database_name); } }
protected override void Execute(CodeActivityContext context) { var database_name = DB_Name.Get(context); var coll_name = Collection_Name.Get(context); var database_ip = DB_Server_IP.Get(context); string Query_Field = Filter_Field.Get(context); dynamic Query_Value = Filter_Value.Get(context); string Update_Key = Update_Field.Get(context); dynamic Update_Val = Update_Value.Get(context); Console.WriteLine(typeoffilter); List <string> output = new List <string>(); MongoClient mongoclient = new MongoClient(database_ip); var db_list = mongoclient.ListDatabaseNames().ToList(); if (db_list.Contains(database_name)) { //Connects to the Exsisting Database or Creates new Database MongoDatabaseBase myDB = (MongoDatabaseBase)mongoclient.GetDatabase(database_name); //Creates new collection //var colll=myDB.CreateCollection(coll_name); var coll_list = myDB.ListCollectionNames().ToList(); if (coll_list.Contains(coll_name)) { var collection = myDB.GetCollection <BsonDocument>(coll_name); if (typeoffilter.ToString() == "EQ") { var query_e = Builders <BsonDocument> .Filter.Eq(Query_Field, Query_Value); var update_1 = Builders <BsonDocument> .Update.Set(Update_Key, Update_Val); // update modifiers collection.UpdateMany(query_e, update_1); } else if (typeoffilter.ToString() == "GT") { var query_e = Builders <BsonDocument> .Filter.Gt(Query_Field, Query_Value); var update_1 = Builders <BsonDocument> .Update.Set(Update_Key, Update_Val); // update modifiers collection.UpdateMany(query_e, update_1); } else if (typeoffilter.ToString() == "GTE") { var query_e = Builders <BsonDocument> .Filter.Gte(Query_Field, Query_Value); var update_1 = Builders <BsonDocument> .Update.Set(Update_Key, Update_Val); // update modifiers collection.UpdateMany(query_e, update_1); } else if (typeoffilter.ToString() == "LT") { var query_e = Builders <BsonDocument> .Filter.Lt(Query_Field, Query_Value); var update_1 = Builders <BsonDocument> .Update.Set(Update_Key, Update_Val); // update modifiers collection.UpdateMany(query_e, update_1); } else if (typeoffilter.ToString() == "LTE") { var query_e = Builders <BsonDocument> .Filter.Lte(Query_Field, Query_Value); var update_1 = Builders <BsonDocument> .Update.Set(Update_Key, Update_Val); // update modifiers collection.UpdateMany(query_e, update_1); } } else { Console.Write("Cannot find Collection"); } } else { Console.Write("Cannot find DB"); } }
protected override void Execute(CodeActivityContext context) { var database_name = DB_Name.Get(context); var coll_name = Collection_Name.Get(context); var database_ip = DB_Server_IP.Get(context); List <FilterDefinition <user_Collection_model> > filter_user = new List <FilterDefinition <user_Collection_model> >(); List <string> output = new List <string>(); //Connects to the Server MongoClient mongoclient = new MongoClient(database_ip); //List of all the Databases var db_list = mongoclient.ListDatabaseNames().ToList(); if (db_list.Contains(database_name)) { //Connects to the Existing Database MongoDatabaseBase myDB = (MongoDatabaseBase)mongoclient.GetDatabase(database_name); //List of all the collections in the database var coll_list = myDB.ListCollectionNames().ToList(); if (coll_list.Contains(coll_name)) { var coll = myDB.GetCollection <user_Collection_model>(coll_name); //The key value combination entered by the user string[] key = Field.Get(context); string[] value = Value.Get(context); //The count of key value combination int count_key = key.Count(); //Builds a list of filters for (int i = 0; i < count_key; i++) { var filter_1 = Builders <user_Collection_model> .Filter.Eq(key[i], value[i]); filter_user.Add(filter_1); } var filter = Builders <user_Collection_model> .Filter.And(filter_user); var results = coll.Find(filter).ToEnumerable().ToList(); for (int j = 0; j < results.Count(); j++) { var i = results[j].CatchAll.ToString(); output.Add(i); } Result.Set(context, output); } else { Console.WriteLine("collection does not exsist"); } } else { Console.WriteLine("DB does not exsist"); } }