Neo4j in Azure mobile services - node.js

I have been trying to use a Neo4j database as my database in an Azure Mobile service. I was following this tutorial and I cant seem to get it to work. Basically what the tutorial does is:
Creates a VM hosted by Azure, running ubuntu and neo4j.
Creates an Azure mobile service with an SQL table.
Writes an insert script for the SQL table that uses node.js to connect to the Neo4j VM and past the data there.
Unfortunately mine does not seem to work. The data gets posted to the mobile services SQL table but the script to post to the Neo4j server on the VM does not seem to work. I also know that the VM is setup correctly because I can connect to it in the Neo4j web admin page.
Here is the code for the script:
function insert(item, user, request) {
//comment to trigger .js creation
var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase('http://<username>:<password>#http://neo4jmobile.cloudapp.net:7474');
var node = db.createNode({ name: item.name });
node.save(function (err, node) {
if (err) {
console.error('Error saving new node to database:', err);
}
else {
console.log('Node saved to database with id:', node.id);
}
});
request.execute();
}
Does any one have any experience with this? Is there something wrong with my script? With the tutorials approach? Any help would be appreciated.
EDIT: There was a problem with the line: console.err('Error saving new node to database:', err); which had to be replace with console.err('Error saving new node to database:', err);. However I am now getting this error message:
Error saving new node to database: { [Error: connect ETIMEDOUT]
stack: [Getter/Setter],
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
__frame:
{ name: 'GraphDatabase_prototype__getRoot__1',
line: 76,
file: '\\\\10.211.156.195\\volume-0-default\\bf02c8bd8f7589d46ba1\\4906fa4587734dd087df8e641513f602\\site\\wwwroot\\App_Data\\config\\scripts\\node_modules\\neo4j\\lib\\GraphDatabase.js',
prev:
{ name: 'GraphDatabase_prototype_getServices__2',
line: 99,
file: '\\\\10.211.156.195\\volume-0-default\\bf02c8bd8f7589d46ba1\\4906fa4587734dd087df8e641513f602\\site\\wwwroot\\App_Data\\config\\scripts\\node_modules\\neo4j\\lib\\GraphDatabase.js',
prev: [Object],
active: false,
offset: 5,
col: 12 },
active: false,
offset: 5,
col: 12 },
rawStack: [Getter] }
Once again, any help would be appreciated!

Did you enable source control and npm install the neo4j module?
Miranda

Ok I managed to figure it out. The problem was that the tutorial (and documentation for neo4j for node.js) had a typo. The code should have been console.error() rather than console.err().

Related

Render Hosted Postgres database throws ECONNRESET on any connection attempt Node Express App

I am unable to query my Postgres DB in Render. I researched this issue online and found that it was a common problem but none of the solutions I found worked.
Here is my server-side code (I am using NodeJS, Express, Typescript and Postgres)
import postgres, { RowList, Row } from 'postgres'
import appconfig from '../app.config'
type Query = (sql: string) => Promise<RowList<Row[]>>
const query: Query = async (sql) => {
try {
const q = postgres({
host: appconfig.database.host,
port: appconfig.database.port,
database: appconfig.database.schema,
username: appconfig.database.username,
password: appconfig.database.password,
})
const res = await q`${sql}`
return res
} catch (err) {
throw err
}
}
export default query
I receive the following error every time and have not had a successful attempt. It's worth noting I have no issues connecting from PGAdmin on the same PC with the same credentials
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
at cachedError (C:\Users\xxxxx\repos\one-watch\node_modules\postgres\cjs\src\query.js:171:23)
at new Query (C:\Users\xxxxx\repos\one-watch\node_modules\postgres\cjs\src\query.js:36:24)
at sql (C:\Users\xxxxx\repos\one-watch\node_modules\postgres\cjs\src\index.js:111:11)
at C:\Users\xxxxx\repos\one-watch\src\database\query.ts:15:24
I have never used postgres before, all of my database experience has been in mysql up to this point, although I don't expect this is a postgres problem but potentially just a nuance of Render's implementation of their Postgres service. Any help would be greatly appreciated, thanks!
The only articles I've found like this one are related but they are able to get at least some sort of successful connection at least once. In my case they are all failing.
Adding
?sslmode=no-verify
in the end of the url worked for me.

Redis sentinel connection is timing out from nodeJS

Am trying to connect redis sentinel instance from nodeJS using ioredis. Am not able to connect redis sentinel instance despite trying multiple available options. We have not configured sentinel password. But, able to connect same redis sentinel instance from .net core using StackExchange.Redis. Please find below nodeJS code,
import { AppModule } from './app.module';
import IORedis from 'ioredis';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const ioredis = new IORedis({
sentinels: [
{ host: 'sentinel-host-1' },
{ host: 'sentinel-host-2' },
{ host: 'sentinel-host-3' },
],
name: 'mastername',
password: 'password',
showFriendlyErrorStack: true,
});
try {
ioredis.set('foo', 'bar');
} catch (exception) {
console.log(exception);
}
await app.listen(3000);
}
bootstrap();
Error we got is,
[ioredis] Unhandled error event: Error: connect ETIMEDOUT
node_modules\ioredis\built\redis\index.js:317:37)
at Object.onceWrapper (node:events:475:28)
at Socket.emit (node:events:369:20)
at Socket._onTimeout (node:net:481:8)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
Connection String used from .net core is below,
Redis_Configuration = "host-1,host-2,host-3,serviceName=mastername,password=password,abortConnect=False,connectTimeout=1000,responseTimeout=1000";
Answering this for the benefit of others. Everything is fine, but this nodeJS package is resolving redis instances into private IPs which i cannot access from my local. So, had to put it over subnet group and make it work. However, FYI - .net core package does not resolve into private IPs, hence i was able to access instances from my local itself.
"The arguments passed to the constructor are different from the ones you use to connect to a single node"
Try to replace password with sentinelPassword.

Mongoose can't connect: Error: querySrv ENOTIMP mongodb.tcp.cluster1-owfxv.mongodb.net

Mongoose can't connect to mogodb Atlas. It every times give me this error:
Error: querySrv ENOTIMP _mongodb._tcp.cluster1-owfxv.mongodb.net
I am running inside kubernetes cluster inside minikube locally.
If I run project directly then it works perfectly but with minikube it alwasy give me error.
Following is my code:
const url = "mongodb+srv://name:password#cluster1-owfxv.mongodb.net/test?retryWrites=true";
const mongoDbOptions = {
useNewUrlParser: true,
reconnectTries: 10,
autoReconnect: true
};
mongoose.connect(url, mongoDbOptions).then((r) => { }).catch((e) => {
console.log(e);
});
Error message is not so clear to me. Its strange that it works directly but with kubernetes cluster it does not work.
I will really appreciate for any contribution.
Try using connection string compatible with mongo driver 2.2.12 or later i.e. one with mongodb://username:password#host1:port,host2:port,host3:port/databaseName
It's not clear why connection to mongodb is not working with new url.
Using older url, as stated by #cEeNikC, even works when mongoose is giving the following error-
Error: querySrv ETIMEOUT _mongodb._tcp.cluster0.aq9un.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19) {
errno: 'ETIMEOUT',
code: 'ETIMEOUT',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0.aq9un.mongodb.net'
}
go to your cluster setting and enable access from all IP addresses (if you doing this for a learning purpose because it's not safe) .
I add this "&w=majority" and worked:
Before: mongodb+srv://:#sdq25.lepde.mongodb.net/myFirstDatabase?retryWrites=true
After: mongodb+srv://:#sdq25.lepde.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

Marklogic 9 + Roxy: can't connect to created database using Node.js

I'm trying out the Roxy deployer. The Roxy app was created using the default app-type. I setup a new ML 9 database, and I ran "ml local bootstrap" using the default ports (8040 and 8041)
Then I setup a node application. I tried the following (sample code from https://docs.marklogic.com/jsdoc/index.html)
var marklogic = require('marklogic');
var conn = {
host: '192.168.33.10',
port: 8040,
user: 'admin',
password: 'admin',
authType: 'DIGEST'
}
var db = marklogic.createDatabaseClient(conn);
db.createCollection(
'/books',
{author: 'Beryl Markham'},
{author: 'WG Sebald'}
)
.result(function(response) {
console.log(JSON.stringify(response, null, 2));
}, function (error) {
console.log(JSON.stringify(error, null, 2));
});
Running the script gave me an error like:
$ node test.js
{
"message": "write document list: cannot process response with 500 status",
"statusCode": 500,
"body": "<error:error xsi:schemaLocation=\"http://marklogic.com/xdmp/error error.xsd\" xmlns:error=\"http://marklogic.com/xdmp/error\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n <error:code>XDMP-IMPMODNS</error:code>\n <error:name>err:XQST0059</error:name>\n <error:xquery-version>1.0-ml</error:xquery-version>\n <error:message>Import module namespace mismatch</error:message>\n <error:format-string>XDMP-IMPMODNS: (err:XQST0059) Import module namespace http://marklogic.com/rest-api/endpoints/config does not match target namespace http://marklogic.com/rest-api/endpoints/config_DELETE_IF_UNUSED of imported module /MarkLogic/rest-api/endpoints/config.xqy</error:format-string>\n <error:retryable>false</error:retryable>\n <error:expr/>\n <error:data>\n <error:datum>http://marklogic.com/rest-api/endpoints/config</error:datum>\n <error:datum>http://marklogic.com/rest-api/endpoints/config_DELETE_IF_UNUSED</error:datum>\n <error:datum>/MarkLogic/rest-api/endpoints/config.xqy</error:datum>\n </error:data>\n <error:stack>\n <error:frame>\n <error:uri>/roxy/lib/rewriter-lib.xqy</error:uri>\n <error:line>5</error:line>\n <error:column>0</error:column>\n <error:xquery-version>1.0-ml</error:xquery-version>\n </error:frame>\n </error:stack>\n</error:error>\n"
}
If I change the port to 8000 (the default appserver that inserts into Documents), the node function executes correctly as expected. I'm not sure if I need to configure anything else with the Roxy-created appserver so that it works with the node.js application.
I'm not sure where the "DELETE_IF_UNUSED" part in the error message is coming from either. There doesn't seem to be any such text in the configuration files generated by Roxy.
Edit: When accessing 192.168.33.10:8040 via the browser, I get a an xml with a similar error:
<error:error xsi:schemaLocation="http://marklogic.com/xdmp/error error.xsd" xmlns:error="http://marklogic.com/xdmp/error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<error:code>XDMP-IMPMODNS</error:code>
<error:name>err:XQST0059</error:name>
<error:xquery-version>1.0-ml</error:xquery-version>
<error:message>Import module namespace mismatch</error:message>
<error:format-string>XDMP-IMPMODNS: (err:XQST0059) Import module namespace http://marklogic.com/rest-api/endpoints/config does not match target namespace http://marklogic.com/rest-api/endpoints/config_DELETE_IF_UNUSED of imported module /MarkLogic/rest-api/endpoints/config.xqy</error:format-string>
<error:retryable>false</error:retryable>
<error:expr/>
<error:data>
<error:datum>http://marklogic.com/rest-api/endpoints/config</error:datum>
<error:datum>http://marklogic.com/rest-api/endpoints/config_DELETE_IF_UNUSED</error:datum>
<error:datum>/MarkLogic/rest-api/endpoints/config.xqy</error:datum>
</error:data>
<error:stack>
<error:frame>
<error:uri>/roxy/lib/rewriter-lib.xqy</error:uri>
<error:line>5</error:line>
<error:column>0</error:column>
<error:xquery-version>1.0-ml</error:xquery-version>
</error:frame>
</error:stack>
</error:error>
If it matters, MarkLogic version is 9.0-3.1. It's a fresh install too.
Any advice?
Based on the comments, it looks like the problem is that the Node.js Client API expects to talk to a REST API endpoint, but the default Roxy configuration is an MVC application. If you haven't already done anything major with your Roxy app, I'd remove it and create one with --app-type=rest.
$ ml new my-app --app-type=rest --server-version=9
$ ml local bootstrap
$ ml local deploy modules
Then try your Node app.

Error when attempting knex seed:run after successful knex migrate:latest for remote database

I'm running the following error when attempting to run knex seed:run against my remote postgres database (not localhost): Knex:Error Pool2 - Error: connect ECONNREFUSED 127.0.0.1:5432.
I am able to run knex migrate:latest successfully and can see that the tables are created on my postgres server, but when I try to seed I get that error. I've run the same migrations/seed file against my local configuration and it has worked without a problem, but when I attempt to seed my heroku postgres instance, it throws this error (I'm not running my local pg service when I'm seeding the new db, which is likely why it's throwing an error).
Any thoughts on why it is attempting to connect to localhost instead of the specified db? Sample of my file provided below:
var User = require("./models/User");
var Project = require("./models/Project");
exports.seed = function(knex, Promise) {
console.log(knex.client.config.connection); //This returns the correct db info.
return knex('user').del()
.then(function() {
return knex('project').del()
}).then(function() {
return new User({id: 1, firstName: "James", lastName: "Lee", phone: "123-456-2000", email: "test#test.com"}).save(null, {method: "insert"});
}).then(function() {
return new Project({id: 1, name: "Test"}).save(null, {method: "insert"});
})
};
This seems to have occurred due to how I was setting up the migrations / seeds. The configurations were actually pulling from two different places, one which had the correct SSL settings in place, the other without (seed file). Adding the correct settings in both places seemed to resolve the issue.

Resources