Error in connection to mongodb atlas from siddhi

216 views Asked by At

I am new to Siddhi, and I am trying to connect to MongoDB Atlas to make an insertion to the database of a collection, but when I configure the parameters and run the code in siddhi editor, it seems that there is no error in the console but it does not add the record to MongoDB. Here is the code:

@App:name("ConectionMongoDBAtlas")

@App:description("Description of conection to MongoDB Atlas")

@sink(type='mongodb',
-- mongodb.uri='mongodb://username:[email protected]:27017,ac-qe2xpea-shard-00-01.cs3wyqb.mongodb.net:27017,ac-qe2xpea-shard-00-02.cs3wyqb.mongodb.net:27017/siddhi?ssl=true&replicaSet=atlas-4drk5v-shard-0&authSource=admin&retryWrites=true&w=majority',
uri='mongodb+srv://username:[email protected]/siddhi?retryWrites=true&w=majority',
collection.name = 'siddhiCollection',
database.name = 'siddhi'

-- secure.connection = 'true',
-- trust.store = 'C:/Users/luis.ortega/Downloads/siddhi-tooling-5.1.0/resources/security/client-truststore.jks',
-- key.store.password = 'mongodb',

-- sslEnabled = 'true',
-- trustStore = 'C:/Users/luis.ortega/Downloads/siddhi-tooling-5.1.0/resources/security/cloud.mongodb2',
-- keyStorePassword = 'mongodb',
-- @map(type='json')
-- @payload('{"name":"{{name}}", "age":{{age}}}')
)
@primaryKey("name")
@index('age')
define table siddhiCollection(name string, age int);

@sink(type = 'log')
define stream BarStream(message string);

@info(name= 'query1')
define stream InsertStream (name string, age int);

from InsertStream
insert into MongoCollection;

I tried to configure mongodb with the store annotation as it is in the documentation and also with the sink annotation.

We don't know if the database SSL certificate issue is a problem, I even added the certificate to the client-trutstore.jks.

1

There are 1 answers

1
Janith Weerasinghe On

I have tried the connection to the MongoDB (but not for the Atlas) with the following steps and it was successful.

  1. Copy the mongo driver[1] to the /lib directory.

  2. Create a database as 'test' and add the user admin to the database.

    db.createUser({user: "admin", pwd: "admin", roles : [{role: "readWrite", db: "test"}]});

  3. Then simulate the siddhi application using tooling UI after deploying the siddhi application[2].

[1] https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver/3.4.2

[2]

@App:name("store-mongodb")

@Store(type="mongodb",mongodb.uri='mongodb://admin:admin@localhost:27017/test') @PrimaryKey("name") @Index("amount:1", "{background:true}") define table SweetProductionTable (name string, amount double);

/* Inserting event into the mongo store */ @info(name='query1') from insertSweetProductionStream insert into SweetProductionTable;

If there are connection issues to the database, there should be error logs in the carbon log file of the tooling. You can check the log file, 'carbon.log' from the location /wso2/server/logs. This is needed to be checked only if you have observed the logs in the console of the browser.