MongoDB Writer node

I am trying to write to MongoDB by using MongoDB Writer node. IT staff have managed to prepare MongoDB server that is accessible from internet for testing purposes.
I use
Host: XXX.XXX.XXX.XXX (hiden from public)
Port: 27017
Auth: Free
It is a test server without username and password.
MongoDB Writer node executed successfully but nothing written to MongoDB. What may be the problem?

I found out that Table to JSON node created empty table. May be I need other techniques to store generated models?
Success.zip (22.0 KB) MongoDB Writer.knwf (1.1 KB)

Is there are any other way to store models in MongoDB?

Hi,
The Problem is that the model is a binary object, which cannot be encoded in JSON unless you use base64 encoding. However, you would need to write out the file, then read it in with a Java Snippet and convert the binary data using Java code. This approach is quite complicated, but I don’t see another way of doing this.
Kind regards,
Alexander

3 Likes

Thank you, Alexander.
Could you suggest any workflow from example server where such technologies applied?

Hi,
I have created an example workflow that encodes a model as base64 and puts it into a JSON document. In the workflow you need to set a proper absolute file path in the Model Writer node. Decoding works very similar, using also a Java Snippet and the Apache commons-codec library.
Kind regards,
Alexander

Base64 Model.knwf (17.0 KB)

3 Likes

Hi,
Based on the workflow I posted earlier, I have created two components and put them on KNIME Hub: Files to Base64 and Base64 to Files.
Kind regards,
Alexander

3 Likes

Thank you very much, Aleksandr,
As I understood you correctly I can convert models before saving to MongoDB by using Files to Base64 and when I need those models, I can read them by MongoDB Reader and convert in KNIME-format by Base64 to Files node before feeding models to Predictor node?

Hello,
Yes, this is the approach I would take.
Kind regards,
Alexander

1 Like

Dear Alexander,
Just one more question. It looks just a little bit weird: I wanted to to speed up my workflow by operating in RAM with models stored in database. But I end up with performing operations within HDD file system. Do you know any solutions to store and retrieve models not through the file system?

Hi,
It’s just a workaround I can think of. You could create a Ramdisk and store the model in there, but it will take away some of your ram while you use it.
Kind regards
Alexander

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.