我试图效仿这个例子: http://jaydata.org/blog/install-your-own-odata-server-with-nodejs-and-mongodb 但它似乎已经过时了,所以在示例的评论中写的我更新了一些代码如下:
data-model(data-model.js文件):
$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文件):
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);
然后当我在Node.js上运行此代码(使用mongo db作为数据库)时,我收到此错误:
500 TypeError:无法读取未定义
的属性'providerConfiguration'(这里是截图) http://ibin.co/1y4cPcAvfK7C
我正在寻找的是如何重写示例以便它可以工作。