1

I am facing an integration error while trying to connect and interact with both GridDB and MongoDB in my application. The error occurs when I attempt to transfer data between the two databases.

// Establish connection to GridDB
GridStoreFactory factory = GridStoreFactory.getInstance();
GridStore gridStore = factory.getGridStore("yourGridStoreConfig");

// Connect to MongoDB
MongoClient mongoClient = new MongoClient("localhost", 27017);
MongoDatabase mongoDB = mongoClient.getDatabase("yourMongoDB");

// Perform data transfer between GridDB and MongoDB
try {
    // Query data from GridDB
    GridQuery<Row> gridQuery = gridStore.query("SELECT * FROM yourGridDBCollection");
    List<Row> rows = gridQuery.fetch();

    // Insert data into MongoDB
    MongoCollection<Document> mongoCollection = mongoDB.getCollection("yourMongoCollection");
    for (Row row : rows) {
        Document document = new Document(row.getString("column1"), row.getString("column2"));
        mongoCollection.insertOne(document);
    }
} catch (Exception e) {
    System.err.println("Integration error: " + e.getMessage())
Integration error: com.mongodb.MongoSocketException: localhost:27017: Read timed out
;
}

// Close connections
gridStore.close();
mongoClient.close();

0 Answers0