From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MongoDB C# dotnet driver load in labview and meet Getcollection error

Current I learn the MongoDB and try to combine into Labview. 

 First I download the labview driver from Mongo offical website. the .net version is 2.0.0.788. It is good to connect to local database and query and insert. But it doesn't support to connect Mongo Atlas(cloud). It will show mongodb+srv://.... string is invalid parameter.

 So I browse the Mongo website that said it needs the driver higher than ver2.5 can support srv record. So I download the driver of 2.5.1 version. But it cannot find getdatabase method. So I search LV and find the root cause is LV not support generic type in load .net assembly.

 I try to download mongo.driver.legacy.dll according to introduce. Then Getconnection, Getdatabase, List database and List collection is ok and feedback the database and collection names. But it meets erro when load Getcollection method. It is show invalid parameters.

 So Does anyone know the detail reason?

0 Kudos
Message 1 of 3
(1,067 Views)

The error show

Error 4 occurred at Invoke Node in test MongoDB.1vi.vi

Possible reason(s):

LabVIEW: (Hex 0x4) End of file encountered.
=========================
Invalid argument or arguments to function call.

image.png

Databasename and collectionname is feedback

0 Kudos
Message 2 of 3
(1,062 Views)

C# testing is ok. Here is source code

 

using MongoDB.Bson;
using MongoDB.Driver;


class Connect
{
[Obsolete]
static void Main(string[] args)
{
var client = new MongoClient("mongodb+srv://username:password@host/test?authSource=admin&replicaSet=atlas-xkdq0z-shard-0&readPreference=primary&appname=MongoDB%20Compass&ssl=true");
var Server = client.GetServer();
var database = Server.GetDatabase("test");
var collection = database.GetCollection("weather");
var list = collection.FindAll();

foreach (var document in list)
{
Console.WriteLine(document["colour"]);
}
}
}

0 Kudos
Message 3 of 3
(995 Views)