[MongoDB] MongoDB Integration To OutSystems

Forge Component
(10)
Published on 2017-02-24 by Barduino
10 votes
Published on 2017-02-24 by Barduino

Hi! I'm having a difficulty integrating my MongoDB database using the MongoDB plugin from Forge. I'm doing the same approach as shown in the MongoDB Demo (i.e. creating a different module for the backend and putting the logic in wrappers) but I was not able to get any results from my query. I also created a structure for the data that is expected to be returned by the database. Maybe I'm missing something somewhere in my module. The option of using REST services is not applicable since I was required to use "pure" OutSystems only.

Can someone please help me with this? Thank you!

Hi Bryan,

A simple MongoDB query will look like this, in Service Studio:

On the MongoDocumentQuery action, you'll have to pass the following parameters:

  • ConnectionString
  • DatabaseName
  • CollectionName
  • FilterJSON

Here's an example:

Afterwards, you'll have to iterate over the query results, deserialize each document into a structure and append it to the resulting list.

In which part of the process are you having problems?

Cumps

David

I have a Movie App in which I am trying to retrieve a single item. I supplied the required parameters as shown on the pics below. Yet whenever I am executing the MongoDocumentGet action, I am not getting any result.



This is my query: 

This is the result when I ran the debugger:

I'm wondering if there is something wrong with the parameters I supplied, or if building a "core module", just like in the MongoDB Demo and implementing it in my project is a wrong idea. I have checked the connection string, database and collection names and I'm sure that they are correct.

Hi again,


The action MongoDocumentGet will try to fetch a Mongo document by its internal identifier (_id).

A equivalent query on Mongo would be:

  db.collection.find( { _id: "your-identifier" });

From what I see, it seems the MovieId you're providing doesn't match with any _id in MongoDB.


Cumps,

David

Sorry for the late reply.

I did a query on MongoDB Compass, and the item exists on the database.



As you can see, it is the same identifier that I used on my query below.


Maybe there is something here that I have missed. I'm still figuring it out though.

Hi Bryan,

Yep it seems correct. Here are a couple of extra things you can check:

  • Are the database and collection names correct?
  • Have you tried querying all documents and check the result?

Hi David!

I tried querying all the documents and it did return my desired result. But whenever I try to query using the MongoDocumentGet, it doesn't return anything. I think I'm almost there. I'm still tweaking around the FilterJSON parameter of MongoDocumentQuery, as well as the id parameter of MongoDocumentGet. 

I will update here ASAP. Cheers!

Update: 

I tried the action MongoDocumentQuery and supplied the FilterJSON parameter, this is the result:

It's empty.

It's the same thing with MongoDocumentGet.

I'm starting to think that the culprit is the argument or the value of the id being passed in the id parameter of those actions.

And also, I'm wondering if the version of OutSystems that I am using has something to do with this problem. I am using OutSystems 11.

Hi Bryan,

What are you passing on the "id" parameter?

Have you tried using MongoDocumentQuery and filtering by other fields?

Regards,

David