MongoDB and CollectionName

Please complete the details below then remove this line:


Volt MX Version: 9.52
**Operating System:**Win11
Database (if appropriate): SQLServer / MongoDB
Server: Tomcat


Problem/Query:
I’m trying to query a MongoDB database, but I don’t know where or how to send the CollectionName instruction. In my function below, I get an error saying that the CollectionName key is required:
login: function(){
var self = this;

function INVOKE_SERVICE_j9600a3726f145db9ec89dd9d9890187_Callback(status, MongoDocument_get) {
voltmx.application.dismissLoadingScreen();
}
voltmx.application.showLoadingScreen(null, null, constants.LOADING_SCREEN_POSITION_FULL_SCREEN, true, true, {});
if (MongoDocument_get_inputparam == undefined) {
var MongoDocument_get_inputparam = {
options: {}
}; }

var odataParams = ;
var select = ;
select.push(“CollectionName eq ‘usuarios’”);
select.push(“email eq '”+self.view.Login.txtUserName.text+“'”);
select.push(“eq password '”+self.view.Login.txtPassword.text+“'”);
select = select.join(" and ");
select = “$filter=” + select;

MongoDocument_get_inputparam[“options”][“odataurl”] = select;
MongoDocument_get_inputparam[“serviceID”] = “usuariosDB$MongoDocument_get”;
var MongoDocument_get_httpheaders = {};
MongoDocument_get_inputparam[“httpheaders”] = MongoDocument_get_httpheaders;
var MongoDocument_get_httpconfigs = {
timeout: 30
};
MongoDocument_get_inputparam[“httpconfig”] = MongoDocument_get_httpconfigs;
usuariosDB$MongoDocument_get = mfintegrationsecureinvokerasync(MongoDocument_get_inputparam, “usuariosDB”, “MongoDocument_get”, INVOKE_SERVICE_j9600a3726f145db9ec89dd9d9890187_Callback);
}

Hi @cristech we are looking into this issue, however, if you are able to open a support case for this issue, we would be happy to assist you. Thank you!

Hello @cristech ,

I wanted to bring your attention to a post in our Volt MX Tips section. It explains how to configure a Mongo DB connection. The post explains that a value must be entered in the $filter to retrieve the correct documents from MongoDB. If this value is incorrect, you’ll get an error.

Please review the post below and let us know if it’s helpful:

Thanks!

Hi @cristech ,

The collection name should be set in the foundry configuration.

  1. If using integration service, the following code (in my case) created in frmMongoCodeController (image 1) will write out the response in the console (image 2):

  1. you can also consider using object service (ensure the service is created in Foundry), image 3 shows the code that will write out the response (image 4).

Image 4

In both cases, you can write the necessary steps in the operationSuccess function().

Hope that helps!

1 Like