javascriptnode.jsmongodbodatajaydata

OData service using NodeJS and JayData


I am trying to follow this example: http://jaydata.org/blog/install-your-own-odata-server-with-nodejs-and-mongodb but it seems to be out of date, so as written in the example's comment i have update some line of code as follow :

data-model (data-model.js file) :

 $data.Class.define ( 
                        "dbTest.tblTest", 
                        $data.Entity, 
                        null, 
                        {
                            ID: {   type: "id", 
                                    key: true, 
                                    computed: true, 
                                    nullable: false 
                                },
                            Data: { type: "string" }
                        }, 
                        null
                    );

 $data.Class.defineEx   (   "dbTest.Context", 
                            [ $data.EntityContext, $data.ServiceBase ], 
                            null, 
                            {
                                tblTest:    {   type: $data.EntitySet, 
                                                elementType: dbTest.tblTest 
                                            }
                                }                       
                    );

 exports = dbTest.Context;

server (server.js file) :

 var c = require('express');
 var bodyParser = require('body-parser');
 var cookieParser = require('cookie-parser');
 var methodOverride = require('method-override');
 var session = require('express-session');
 var errorhandler = require('errorhandler');
 require('jaydata');
 window.DOMParser=require('xmldom').DOMParser;
 require('q');
 require('./data-model.js');
 var app = c();
 app.use(c.query());
 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({ extended: true }));
 app.use(cookieParser());
 app.use(methodOverride());
 app.use(session({ secret: 'session key' }));
 app.use("/dbTest", $data.JayService.OData.Utils.simpleBodyReader());
 app.use("/dbTest", $data.JayService.createAdapter(dbTest.Context, function (req, res) {
 return new dbTest.Context({name: "mongoDB", databaseName:"test", address: "127.0.0.1", port: 27017 });
 }));
 app.use("/", c.static(__dirname));
 app.use(errorhandler());
 app.listen(8080);

Then when i run this code on Node.js (using mongo db as database) i get this error :

500 TypeError: Cannot read property 'providerConfiguration' of undefined

(here the screenshot) http://ibin.co/1y4cPcAvfK7C

What i looking for is how to rewrite the example so that it can work.


Solution

  • So the fix for me was to install the mongodb package from npm

    npm install mongodb
    

    and also insert some data.

    enter image description here