Uipath and MongoDB connectivity

You may use Invoke Code Activity

  1. Add the MongoDb package.
    MongoDB.Driver 2.11.2

  2. Import the namespace.

  3. You can use Invoke Code activity
    image

  4. Add the following C# code

     var client = new MongoClient("<mongo-db-string>");
     Console.WriteLine("Client"+client);
    
     // get the test database
     var db = client.GetDatabase("test");
     Console.WriteLine("db"+db);
    
     // gets a collection named "foo" using a BsonDocument
     var collection = db.GetCollection<BsonDocument>("sample8");
     Console.WriteLine("collection"+collection);
    
     var document = new BsonDocument("x", 1);
     collection.InsertOne(document);
    

Let me know. If the Invoke code errors out with CS1003. Just restart Studio and it should work as it reloads the libraries.

5 Likes