How to retrive data from backend service on apigee edge using NO Sql database

Not applicable
 
0 7 912
7 REPLIES 7

@A.Anu Manasa

Could you elaborate on your use case please ? You want to retrieve data from a backend which is a NoSQL Database ?

Details would help us recommend appropriate next steps.

yes i want to retrieve data from backend i.e is no sql data base from apigee edge

@A.Anu Manasa

Any specific NoSQL database you are referring to ? Are in general ? Because there are many NoSQL databases.

Not applicable

Hi @Anil Sagar

Yes I want to use MongoDB database.If I want to retrieve data from the table which is created on MongoDb database through the apigee edge by writing java call out.Is it possible.can you please help me?

adas
New Member

@A.Anu Manasa Yes, you could do this in node.js using the mongodb npm modules. Something like this should work:

var MongoClient = require('mongodb').MongoClient
    , format = require('util').format;

MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
    if(err) throw err;

    var collection = db.collection('test_insert');
    collection.insert({a:2}, function(err, docs) {
        collection.count(function(err, count) {
            console.log(format("count = %s", count));
        });
    });

    // Locate all the entries using find
    collection.find().toArray(function(err, results) {
        console.dir(results);
        // Let's close the db
        db.close();
    });
});

You can also use the mongodb-core npm module, more details available here: https://www.npmjs.com/package/mongodb-core

Could you please give clear information where I want to write this client code and server code in Apigee Edge?Please let me know .

Hi @A.Anu Manasa

While creating the API Proxy, add it as node js app as soon in the screenshot below -

screen-shot-2016-10-25-at-44634-pm.png

Once you build and deploy the API proxy with Node Js App as back-end, go to the develop section of the proxy as below -

screen-shot-2016-10-25-at-45040-pm.png

add the above code to helloworld.js (default file) to make a connection to MongoDB and get the details from the DB, and return it as response.

You can use routing optionally to use the above mentioned Mongo Helper Methods to route the request to MongoDB and create a response after getting the details.

You could additionally manipulate the response content as required using other policies, available out-of-the-box.

Kindly go through the sample proxies available for Node JS to get the better understanding.

In the following scenario, Apigee Baas acts as an NoSQL DB.

http://docs.apigee.com/api-services/cookbook/building-baas-service-nodejs

Hope this helps for you, Thank You.