I've written a simple Java server. The basic idea is that, upon clicking a button, a servlet will load some data into MongoDB.
However, whenever I try to actually load something into MongoDB (in my case, saving a collection), I get the following error:
com.mongodb.MongoException$Network: can't call something : /127.0.0.1:27017/
com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:295)
com.mongodb.DBTCPConnector.call(DBTCPConnector.java:257)
com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:310)
com.mongodb.DB.command(DB.java:274)
com.mongodb.DB.command(DB.java:256)
com.mongodb.DB.command(DB.java:313)
com.mongodb.DB.command(DB.java:211)
com.mongodb.DB.createCollection(DB.java:170)
servlets.ImportData.doPost(ImportData.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
Does anyone know what the issue here might be? When I searched this problem I found people guessing at everything from port conflicts to stale connections to incorrect installation of MongoDB, so it would be fantastic to get some clarity on this one.
If it helps to see the source code, I'd be more than happy to share it.
Thanks in advance!
Turns out my instance of mongod wasn't running at the time I was executing the commands.
Make sure to run "mongod" in your console at all times you're using the server.
The second error I encountered was failing to specify the host and port of the MongoClient, in the following way:
MongoClient mongo = new MongoClient();
Instead you can do:
MongoClient mongo = new MongoClient("localhost", 27017);
You can stick that into your servlet context and pass it around as needed to other servlets, and while I have declared MongoClient mongo with the new statement here, I would recommend keeping it as a class variable of the ContextListener.
Related
I had configured the JDBC connection configuration in the pipeline.
and when the application executes i get the following error on the logs.
"java.sql.SQLSyntaxErrorException: Table 'databaseName.aim_table' doesn't exist"
The databaseName is not what I have set.
I have tried many times. it shows the same message that could not find the table in different database, and the question is all the db occurred in the sdc.log are that I had never configured ,and the correct database is never used ,so I want to know how could it find the wrong db and I had checked before start the pipeline and it shows successful:
Do you have anything set in the Schema Name configuration for JDBC
Producer? This should be blank for MySQL, since you're setting the
database/schema name in the connect URL.
Check that your MySQL driver matches the server. In particular, using
the current version 8.0.x JDBC driver with a 5.x.x server seems to
result in this problem. Download the older 5.1.x driver (currently
5.1.46) and it should work.
refer this
This problem is indeed caused by the wrong version of the driver package. I found the correct driver package and successfully wrote the data to the target table. add aonther point, I have set the SCHEMA NAME to blank and defined the database name in the connect URL for mysql.
My English is not good. Please forgive me.
Using the new mongodb driver: https://github.com/mongodb/mongo-php-driver and the new php library for it: https://github.com/mongodb/mongo-php-library I am getting "auth fails" trying to perform a simple find() query.
In the following code, the connection string follows the pattern mongodb://user:password#mongoinstance:port/database. The connection string works with find() using the old legacy mongo driver, but not the new mongodb driver. The new mongodb is correctly installed in php and displays in phpinfo, the only breaking change we needed to make was to use "new MongoDB\Client" instead of new MongoClient for the legacy mongo driver.
However, when I try to run the following find(), I get auth fails exception in vendor/mongodb/mongodb/src/Operation/Find.php line 179
Using legacy mongo driver there are no problems. Any ideas on the auth fails? What is the mongodb driver failing on exactly? Correct credentials for database and collection are being passed in the mongodb://string. Works in legacy fails with new driver and library.
Environment:
Windows 10
Wamp
PHP 5.5.12
Mongodb driver 1.1.4
Latest version of new php library (Installed with composer: composer require "mongodb/mongodb=^1.0.0")
Mongo instance version 2.4.6
I just had the same error and found out that I had to place the database-name in the connection string.
The documentation here says:
If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database.
And the user I'm using has no rights to the admin-database, so this is why I received the authentication error.
I advise you to check this too. You can't provide the database-name the same way as with the MongoClient via the connection options.
So here's the solution. After 3 days of banging my head against a wall it turns out the new mongodb driver parses the mongodb uri differently than the legacy mongo driver. My password had a % sign in it. As soon as I changed the % sign to something else everything worked as expected.
I've set up my own local mongodb (v. 3.0.2) instance on a local ubuntu version (14.10) and I'm using genghis(v. 2.3.11) to visualize it. My programm is able to create new documents in the database, but when I try to save a newly created document or delete a document in genghis it always returns "j must be numeric or a boolean value" but it still creates/deletes the document. The error doesn't show up when I edit a document. The only thing I could find when I tried to find a solution on google was this: https://github.com/mongodb/mongo/blob/master/src/mongo/db/write_concern_options.cpp which makes me think that it's a problem with my mongodb setup (and has nothing to do with genghis), but I do not know how to resolve this.
Have you tried running the code against Mongo 2?
I ran into this same error when I tried connecting to Mongo 3 from a service that was using client libraries intended for Mongo 2.
I have my MONGO_URL set to mongodb://localhost:27017/meteor and have the MongoDB run as a service.
When running my project it seems OK to store data to the separate MongoDB until I tried to run meteor reset.
My assumption is it tried to remove its default database. The error complained that myproject.meteor\local is not empty and pointed to fs.js:456 which goes to files.js:256 (rm_recursive) and so on.
any idea what and how I can fix this?
$ meteor reset only resets the bundled MongoDB. It won't reset an external Mongo database.
(That's something we should explain better in the documentation.)
In your case, try connecting to the Mongo database directly (with the mongo command line shell) and running > db.dropDatabase()
Are there any recent working examples on using Dart with MongoDB. All of the samples I'm trying are getting errors. Example below.
Code:
import 'package:mongo_dart/mongo_dart.dart';
main(){
Db db = new Db("mongo-dart-blog"); // Throws an error.
}
Error:
Unhandled exception:
Invalid scheme in uri: mongo-dart-blog
#0 Db.Db (package:mongo_dart/src/database/db.dart:25:7)
#1 main (file:///.../MongoDart/app.dart:4:11)
I believe you are running some old versions of mongo_dart samples.
I belive if you would get fresh version either from github https://github.com/vadimtsushko/mongo_dart or from pub.dartlang.org samples and tests would run successfully.
Corresponding line in fresh version of blog sample looks like:
Db db = new Db("mongodb://127.0.0.1/mongo_dart-blog");
And this is excerpt from comment for Db.open method
Db constructor expects valid mongodb URI.
For example next code points to local mongodb server on default mongodb port, database testdb
var db = new Db('mongodb://127.0.0.1/testdb');
And that code direct to MongoLab server ds037637-a.mongolab.com on 37637 port, database blog, username dart, password test
var db = new Db('mongodb://dart:test#ds037637-a.mongolab.com:37637/blog');
Unfortunately API DOC on github site is very stale, due to old dartdoc bug:
http://code.google.com/p/dart/issues/detail?id=5218
I hope it will be fixed soon and I'll be able to generate valid API doc for mongo_dart.
I've had a lot of trouble with MongoDB in client-side Dart myself. I ended up moving the Mongo calls to the back end, and using a combination of REST and Json to communicate between the two ends. You can find an example I wrote at https://github.com/RossBabcock3/dartgo3