Articoli e notizie

Il blog di Eld Engineering

Eld Engineering Srls

Home > News > Domino and node.js: first steps (part 3)

Domino and node.js: first steps (part 3)

by | 2 May 19 | Domino e Notes 10, Sviluppo Domino e Notes


 Vai alla versione in Italiano

Our journey in the setup and use of node.js with Domino 10 continues here.

If you missed the previous articles you can find them here: part 1 and part 2 .

I suggest you to read it before continuing as the first points are necessary to start creating the environment. This article starts from point five.

(This article is the third of a series, we will update the links as we proceed to publish everything)

 

5. The node.js code

Now I started to make some tests with Node.js. I already has a sample database that contains 19.000 documents, is a public database made available from Regione Lombardia that contains all the hotels and accomodations in Lombardia.
I started from the excellent example by Oliver Busse (https://oliverbusse.notesx.net/hp.nsf/blogpost.xsp?documentId=2E52) and my final objective is to interrogate the database by provincia (the Italian equivalent for county).

Let’s see in the beginning how to declare the connections to the Domino server from Node.js:

// domino-db
const {
    useServer
} = require('@domino/domino-db');

// certificati
const fs = require('fs');
const path = require('path');
const readFile = fileName => {
  try {
    return fs.readFileSync(path.resolve(fileName));
  } catch (error) {
    console.log("Errore leggendo " + fileName);
    return undefined;
  }
};
const rootCertificate = readFile('ca.crt');
const clientCertificate = readFile('app1.crt');
const clientKey = readFile('app1.key');

// proton config
const serverConfig = {
    "hostName": "xxxxx.yyyyyy.it",
    "connection": {
        "port": 3002,
        secure: true,
    },
      credentials: {
    rootCertificate,
    clientCertificate,
    clientKey,
  },
};

The first part(domino-db) calls the module domino-db that we installed previously.

Then we have the part of the certificates, where I read the three files needed for the connection that I creates before in point 4: ca.crt is the root certificate, the other two are those of the user App1 (for which we created the person document in the NAB).

Last we have the proton config part where is declared the connections to the server as secure and are passed the three files with certificates and key. The port 3002 we have configured in point 2.

Now Node.js should be able to connect to the Domino server and with this instruction we can tell him which database to use:

// domino nsf
const databaseConfig = {
"filePath": "node/struct.nsf"
};

Then you have to declare the query:

var query = "PROVINCIA = 'VA'"

if you already worked with DQL this is really straightforward.

The last is a variable

const maxCount = 200;

which is the max number of results the query can return .

Here unfortunately there is what I think is currently a pain point: the 200 value for the maxCount was not just an example but it is the maximum value that the domino-db module can return.

 

In other words, if the query returns more than 200 records ​​(through the bulkReadDocuments call) the domoni-db module in node.js cannot handle them !

So, If we suspect to have more than 200 documents returned from the query we will have to manage them using the node.js code and the start parameter which indicates to bulkReadDocuments from which position to start:

        const docs = await database.bulkReadDocuments({
           query: query,
           count: count,
           start: 400,
           itemNames: ["CAP", "NOME_COMUNE", "DENOMINAZIONE_STRUTTURA", "INDIRIZZO"]
        });

Another thing to keep in mind is the declaration of the fields (itemNames) we want to be returned by the query, there is no default and if we omit it the query returns nothing (i.e. no fields).

 

As by now you can see the result here: http://posta. eldeng.it:8080/

0 Comments