MongoDB Rust Client Connection Errors - mongodb

I am a Rust newbie and am trying to create a REST API using actix and mongodb.
Before starting up the I am trying to connect to a local MongoDB instance Using the official rust client from here. Here is the code I am trying
let client = Client::with_uri_str("mongodb://localhost:27017").expect("Error getting client");
let database = client.database("mydb");
let collection = database.collection("books");
Rustc version is 1.44 and MongoDB driver version 1.0.0
While running this code, I do not get an error if the local mongodb server is not running.
How do we figure out if the connection to the DB has been successful or not ? No point continuing if the DB connection itself is not established.

The drivers are required to establish connections in the background. Instantiating a client is supposed to always succeed.
The purpose of this is to, for example, allow the application and the database to be started at the same time - when the database becomes available, the application will be able to use it.
To find out whether your database is operational, execute a command such as ping. Most applications will simply carry on with their normal queries/updates.

Related

How to initialise a mongokitten server globally in a swift file other than the main.swift file?

I use mongodb to store all data of my mac application.So I use Mongokitten library as the interface between the db and my app. Inorder to connect to db initially and maintain the connection throughout the time when application is running I need to establish a one time connection to db. But I'm not able to initialise the server globally in the swift file.What i do is connect to the server each time a operation(insertion, updation, deletion, read) is performed.This causes the connection to the server to be lost once when these operations are executed over a limit and causes my application to hang. Can anyone please help me find a solution to make the server connection only once for throughout running of application?
I found the answer.Implicitly unwrap the server variable and assign value to server on checking server connection.
For reference follow the link :https://swiftmodules.com/planteam/mongokitten

running camunda with Spring boot & mongodb

Has anyone been able to get Camunda to run with Spring Boot and mongodb?
I tried several approaches and always got into a brick wall.
What I tried:
1. jpa / hibernate-ogm
I was able to initiate a connection to mongo after creating my own CamundaDatasourceConfiguration and ProcessEngineConfigurationImpl.
It failed when Camunda tried to get table metadata. I couldn't plug out this behavior.
2. jdbc driver for mongo by progress
I set up the jdbc url and driver class by progress.
Camunda then gets stuck during the startup process and does not get to the point where Jetty is fully started, i.e. the "Jetty started on port XYZ" message in the log.
3. camunda with postgres with mongo FDW
FDW is a mechanism for postress to interface an external datasource. This way an application can work with postgres over jdbc while the FDW will take care of reading and writing the date to the external source, be it a file, mongodb, etc.
After realizing 1 and 2 don't work, I started working on 3.
Has anyone succeeded in doing this and can share how?
so I ran into the same problem and decided to share my answers with you.
Currently it is not possible to run the Camunda-Engine with a NoSQL Database.
In this Camunda-Forum-Post one of the guys at Camunda also says it is not possible to run the engine completely without a database.
And in the offical Camunda-Docs there is also a list with all supported environments. Currently there are only SQL-Databases listed:
https://docs.camunda.org/manual/7.10/introduction/supported-environments/
But in some earlier Blog-Posts they metioned, that they want to make some proof-of-concept examples with the use of NoSQL-Databases. So we can expect, that these databases will be supported in the future, but not at the moment.
(note: the flowable engine is doing the same proof of concepts, they mentioned, that they want to be able to use NoSQL-databases by the end of the next year).

Not possible to use server after db = server.use?

I was doing a very basic test using node.js, latest orientjs and latest OrientDB:
open server (using port 2424)
assign db (server.use)
server.list()
If I do this, the promise at server.list() hangs and the server shows the error "Impossible to read a chunk of length...". But if I just don't assign the db, it works fine. Also, if I call db functions (like db.record.get) instead of server.list(), that works fine too.
Is it the case that you can't call a server function after calling server.use?
On a related point, is there a way to set a network timeout for orientjs? If I try to do any of this and the target server is not reachable, it just hangs on opening the server and/or assigning the database.

Testing connectionTimeout threshold using Mongo Java driver 3.0.0

Mongo m = new MongoClient(new ServerAddress(server , port), creds, MongoClientOptions.builder().connectTimeout(2000).socketTimeout(2000).serverSelectionTimeout(10000).socketKeepAlive(true).build());
I want to test connectionTimeOut to a standalone server. Every time I define the wrong port for a client or stop the server, it fails on the select server step and returns a serverSelectionTimeOut. How can I test the connectionTimeOut threshold in a development environment?
You need to make sure that you are connecting to an existing server (hostname and port), because the connection is setup after the server-selection process. If server selection fails it won't go to the connection-setup step.
If there is no Mongo server that is always available for testing, try deploying an embedded Mongo server on the fly on your local machine instead. You could write a unit test that automatically launches the embedded Mongo at the start of the test (as is demonstrated here).
Alternatively you could use MongoUnit for testing, but I have no experience with that myself.
Once you have a proper server you can force a connectionTimeout, by setting the timeout value to 1 millisecond. You can do that in code
MongoClientOptions.builder().connectTimeout(1)
or by adding a setting to your database-url
mongodb://localhost:27017/your_database?connectTimeoutMS=1

Not able to migrate the data from Parse to local machine

as some of you might aware about the shutting down of parse service in about a year, i am following the migration process as per their tutorials. However, i am not able to migrate these data from parse to local database(i.e. mongodb).
I've started the mongodb instanse locally on 27017, and also created an admin user as part of migration based on these tutorials. Reference-1 & Reference-2.
But when i try to migrate the data from parse developer console, i get No Reachable Servers or Network Error & i don't understand why. I have doubt in the Connection string that i use for this but i am not sure, please find the following image.
I am new to mongodb so don't have much idea about this, your little help would be greatly appreciated.
Since the migration tool runs at parse.com, the tool needs to be able to access your MongoDB instance over the Internet.
Since you're using a local IP (192.168.1.101), parse.com cannot connect to your IP and the transfer will time out.
Either you need to make your MongoDB reachable from the Internet, or you can - as they do in their guide - use an existing MongoDB service.