Connect to z/TPF support for MongoDB on the z/TPF system

Before MongoDB remote clients can access the z/TPF data, you must connect the MongoDB remote clients to the z/TPF server for MongoDB that you defined and authenticate the MongoDB remote clients.

To connect to z/TPF support for MongoDB, you must create a MongoClient object. The MongoClient object defines the z/TPF server for MongoDB and the authentication credentials that are used when the remote client connects to the z/TPF server for MongoDB.

To connect to z/TPF server for MongoDB, you can create a ServerAddress object, which is passed as a parameter when you create the MongoClient object. The ServerAddress object defines the IP address or host name of the z/TPF system and specifies the port number that the z/TPF server for MongoDB listens to.

To authenticate the remote client, you must create a MongoCredential object, which is passed as a parameter when you create the MongoClient object. The MongoCredential object consists of a user name, password, and database to authenticate against. The following authentication mechanisms are supported for the z/TPF system:
  • MongoDB Challenge Response (MONGODB-CR) protocol

    You can use the createMongoCRCredential() method to create a MongoCredential instance for the MongoDB Challenge Response protocol.

  • PLAIN Simple Authentication and Security Layer (SASL) mechanism

    You can use the createPlainCredential() method to create a MongoCredential instance for the PLAIN SASL mechanism.

Depending on the mechanism that you use, the MongoDB authentication user exit (UATH) is called on the z/TPF system to authenticate the user name and password. For more information about updating the MongoDB authentication user exit (UATH), see Preparing the z/TPF system for data access by using z/TPF support for MongoDB. For more information about the user exit interfaces and examples for the MongoDB authentication user exit (UATH), see the comments in the user exit (uath.cpp).

When the connection is established, a single socket that is used to receive subsequent requests and send corresponding responses is created. Each request that is passed on this socket connection is processed in a new ECB that is started by calling the activate_on_receipt socket function.

The following example shows how to connect to z/TPF support for MongoDB by using the MongoDB Java™ client driver. In the example, ztpf.mydomain.com is the host name of the z/TPF system, and 27017 is the port number of the z/TPF server for MongoDB. The remote client is authenticated by using the mongoUser user name and the mongoPwd password for the tpfdf database.
MongoCredential credential = MongoCredential.createPlainCredential("mongoUser", 
                             "tpfdf", "mongoPwd".toCharArray());
ServerAddress checkIn=new ServerAddress("ztpf.mydomain.com", 27017);
MongoClient mongoClient = new MongoClient(checkIn, Arrays.asList(credential));