Friday 5 May 2017

JayData odata-server configured with sqlite, but reports Mongo error: MongoError: connect ECONNREFUSED 127.0.0.1:27017

I'm setting up an OData service to a SQLite database using odata-server via NodeJS v7.7.4 on a Windows 7 laptop. I've tried to follow the JayData documentation along with advice from the following sources:

Even though I've specifically declared the provider to be "sqLite", when I run the server and test the endpoint, I get the following errors referencing error connecting to mongodb. As you can see in my code, I'm not referencing mongodb. I'm trying to connect to a local sqlite database file.

I'd love to know what I'm doing wrong. Thanks for your time.

Below is my code in a file src/app/server.js:

require('odata-server');

$data.Entity.extend("$rice.types.Rice", {
    Id: { type: String, required: true, maxLength: 20 }, //type: "id", key: true, computed: true },
    Name: { type: String, required: true, maxLength: 200 },
    Type: { type: String, required: true, maxLength: 40 },
    Track: { type: String, required: true, maxLength: 40 }
});
console.log('$rice.types.Rice: '+$rice.types.Rice);

$data.EntityContext.extend("$rice.types.RiceContext", {
    Rices: { type: $data.EntitySet, elementType: $rice.types.Rice }
});
console.log('$rice.types.RiceContext: '+$rice.types.RiceContext);

$rice.context = new $rice.types.RiceContext({ 
    name: "sqLite", 
    databaseName: "RiceDB", 
    dbCreation: $data.storageProviders.DbCreationType.DropTableIfChanged });

$data.createODataServer($rice.types.RiceContext, '/rice', 52999, 'localhost');

I run this as such:

node src/app/server.js

Here is the output from running the file as noted above:

Should be empty: []
$rice.types.Rice: function Rice(){
    //mixins

    //construction
    var baseArguments = $data.typeSystem.createCtorParams(arguments, base[0].params, this);
    $data.Entity.apply(this, baseArguments);

    //propagations

}
$rice.types.RiceContext: function RiceContext(){
    //mixins

    //construction
    var baseArguments = $data.typeSystem.createCtorParams(arguments, base[0].params, this);
    $data.EntityContext.apply(this, baseArguments);

    //propagations

}

To test the service, I access the endpoint at: http://localhost:52999/rice

When I try to access the above-noted URL, I get the following response in the web browser:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<service xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://www.w3.org/2007/app" xml:base="http://localhost:52999rice/">
<workspace>
<atom:title>Default</atom:title>
<collection href="Rices">
<atom:title>Rices</atom:title>
</collection>
</workspace>
</service>

My above test results in the following being generated in the console window where I ran "node src/app/server.js":

body-parser deprecated bodyParser: use individual json/urlencoded middlewares node_modules\odata-server\index.js:58:13
body-parser deprecated undefined extended: provide extended option node_modules\odata-server\node_modules\body-parser\index.js:85:29
{ MongoError: failed to connect to server [127.0.0.1:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (D:\Users\richard.lyders\Documents\dev\rice\node_modules\mongodb-core\lib\topologies\server.js:328:35)
    at emitOne (events.js:96:13)
    at Pool.emit (events.js:191:7)
    at Connection.<anonymous> (D:\Users\richard.lyders\Documents\dev\rice\node_modules\mongodb-core\lib\connection\pool.js:274:12)
    at Object.onceWrapper (events.js:293:19)
    at emitTwo (events.js:106:13)
    at Connection.emit (events.js:194:7)
    at Socket.<anonymous> (D:\Users\richard.lyders\Documents\dev\rice\node_modules\mongodb-core\lib\connection\connection.js:177:49)
    at Object.onceWrapper (events.js:293:19)
    at emitOne (events.js:96:13)
  name: 'MongoError',
  message: 'failed to connect to server [127.0.0.1:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]' }

Again, thanks for any help with this.

Best wishes



via RJLyders

No comments:

Post a Comment