LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview interface with MongoDb or similar NoSql database

Hollowhorse,

Thank you that helps a lot, if I wanted to use the "$set" operator or the "$push" operator, how would I go about doing that? do I include it in the "name" input of the "update document"? I'm trying to recreate the following piece of python code in labview.

 

db.finalstage.update({'_id':id},{"$push":{'log_file_array':log_file_array}})
db.finalstage.update({'_id':id},{"$set":{'finalstage_test_flag':'F'}})

 

Thanks in advance,

 

-exXo

0 Kudos
Message 31 of 51
(2,857 Views)

Hi exXO, Try this, I've assumed the data type for the log_file_array is string.

 

This creates the two update documents in your python code...

push and set1.png

 

Or, if you are modifying the same document in both updates then you can combine the operators into one update...

push and set2.png

 

Creating BSON docs in LabVIEW via .NET can get a bit long-winded, but it's pretty straightforward once you get your head around it. One of the first things I did was write some VI's to encapsulate the .NET calls, which made the process much simpler. I've been meaning to post these somewhere, but I've never found the time to write any proper documentation for them.

 

Regards,

Hollowhorse

Message 32 of 51
(2,852 Views)

Hollowhorse,

 

Thanks so much for your feedback, this has helped me a lot. saved me a lot of headaches. Thanks again, you are awesome!

 

-exX0

0 Kudos
Message 33 of 51
(2,848 Views)

You're very welcome. I'm glad it helped 🙂

 

Hollowhorse

0 Kudos
Message 34 of 51
(2,842 Views)

Hello again, I'm not very familiar with .Net, How do I, instead of constructing a BsonString, construct a BsonArray of Strings? the log_file_array above mention is actually an array of strings that I would need to update using the $push operator.

 

Thanks in advance,

-exXo

0 Kudos
Message 35 of 51
(2,831 Views)

Arrays in a BSON document (unlike LabVIEW) don't have a type. They represent an array of values, but the value type can be different for each element in the array. So element 0 might be a string and element 1 could be another string, but it doesn't have to be.

 

To create a BSON array in LabVIEW, use the Array .NET constructor. Once the document with your array is added to your database, you can then add successive elements, of any type, to the array using the $push operator.

 

Alternatively, the $push operator will create the array in your target document if it doesn't already exist - Which is even easier 🙂

 

I hope this helps,

Hollowhorse

Message 36 of 51
(2,821 Views)

First of all, thanks for all the answers in this thread.

I want to only update only one key/parameter of the document not the entire contents. How do I do this?

Regards,

Saptarshi Pan

0 Kudos
Message 37 of 51
(1,988 Views)

Hi Saptarshi,

 

I'm assuming you want to update a document that already exists in a MongoDB collection? If so, you need to use the MongoDB $set Operator. This sets the value of a specific entry without affecting the rest of the document. There are some examples of of how to use the $set Operator eariler in this thread, and you can find a detailed explanation of what it does here: https://docs.mongodb.com/manual/reference/operator/update/set/ 

 

Regards,

Hollowhorse

 
Message 38 of 51
(1,964 Views)

Hi Hollowhorse,

Thank you so much. I immediately realized the solution after posting the question.

Now, I am facing a problem in sending ISO Date/Time to the database. Can you help me in that? Currently I have used a method which stores the ISO Date/Time value in string format, but I don't want that.

Also, a side question, is the programs that are made using the LabView Driver for MongoDB (https://github.com/RBXSystems/mongo-labview-driver, developed on .NET) does these work in CRIO (in Linux Environment)?

Regards,

Saptarshi Pan

0 Kudos
Message 39 of 51
(1,948 Views)

Hi,

I started out using the official Mongo C# driver, which I accessed using LabVIEW's .NET support. Later on, I developed a driver by encapsulating .NET calls into VI's. This is very similar to the approach taken by the RBX Systems driver. I did the extra work of creating a driver because my application was quite complex, so it made sense to spend the time creating a re-usable platform for the database code. In your case, you might find just stringing together a few .NET nodes is enough.

Because .NET is Microsoft tech, I'm pretty sure it'll only work on Windows. However, there are alternative drivers for C, JAVA, Python, etc... so you might find another driver that better suits your use case.

Regarding ISO date conversion: The .NET BsonDateTime object provides a AsDateTime property which will give you the date and time as a LabVIEW timestamp. If you're working with general BSON value class objects, you will have to cast these to BsonDateTime first.

I hope this helps.

0 Kudos
Message 40 of 51
(1,933 Views)