Mongeez with spring boot - mongodb

I have some set of MongoDB insert commands to be executed during the application startup. refered https://github.com/hzpz/mongeez-spring-boot-starter for my requirement
Followed the below steps
1) Added the dependency in pom
2) Created js and mongeez.xml in an external folder
3) Referred the location in mongeez.location={myDir}/db
I am getting below exception while starting the application
Caused by: com.mongodb.MongoCommandException: Command failed with error 59 (CommandNotFound): 'no such command:
'$eval'' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "no such command:
'$eval'", "code": 59, "codeName": "CommandNotFound"}
The contents of the js file is
db.organization.save({"Name" : "10Gen", "Location" : "NYC"});
the contents of mongeez.xml is
<changeFiles> <file path="config.js"/> </changeFiles>
Spring Boot Version : 2.2.1.RELEASE
Mongeez Version : 2.0.1

The db.eval() command is not supported after mongo:4.2 verison.
check this link 'no such command: '$eval'' on server localhost:27017
Let me know, if you found something, in the mean time we can only go back to mongo:4.0 or start using mongobee https://github.com/mongobee/mongobee

Related

Appsmith server is not starting because of MongoDB exception

My Appsmith instance just upgraded to v1.6.4 and it's not booting up anymore. In the logs, I can see the exception below:
Caused by: com.mongodb.MongoCommandException: Command failed with error 17 (ProtocolError): 'Attempt to switch database target during SASL authentication.' on server mongo:27017. The full response is {"ok": 0.0, "errmsg": "Attempt to switch database target during SASL authentication.", "code": 17, "codeName": "ProtocolError"}
Is there anything I can do to bring up my Appsmith instance?
This is a breaking change that was introduced in v1.6.4 of Appsmith because of Spring library upgrades. A complete fix is described at: https://docs.appsmith.com/troubleshooting-guide/deployment-errors#server-not-booting-because-of-mongocommandexception
Step 1: Edit MongoDB URI
Adding &authSource=admin to the end of your APPSMITH_MONGODB_URI variable’s value in your docker.env file. For example, in your docker.env file, if you have the following line:
# Old config
APPSMITH_MONGODB_URI=mongodb://<your_username>:<your_password>#mongo/appsmith?retryWrites=true
Change it to the following (notice the only change is &authSource=admin. Do NOT copy-paste this whole line. Only add the &authSource=admin part to your existing value.
# New config
APPSMITH_MONGODB_URI=mongodb://<your_username>:<your_password>#mongo/appsmith?retryWrites=true&authSource=admin
Save the file.
Step 2: Restart server
Now restart your container with the following command:
sudo docker-compose up -d --force-recreate appsmith-internal-server
In a minute or two, the server should now come up and be ready.

IntelliJ Database explorer won't work with localhost Mongo 4.4.3

I'm up-the-middle MongoDB with authentication localhost. I have the mongod configured to bind a specific user to a specific database and from the mongo shell and my Java programs, everything works great. When I log in as that user I can do all the mongo stuff on the mongo db I bound that user to.
$ mongo -u totallyLegitUser --authenticationDatabase admin
MongoDB shell version v4.4.3
Enter password:
connecting to: mongodb://127.0.0.1:27017/?authSource=admin&compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("2ba7a3f6-2ca1-49b7-8241-8133ceb3d842") }
MongoDB server version: 4.4.3
> use mfg-plan;
switched to db mfg-plan
> show collections;
activity
...
When I try to set up the same user through IntelliJ's "Database" thing, the "Test Connection" says everything is fine, but I can't run any queries through the console and the "explorer" drop down thing doesn't show collections I know are in the database.
This is what shows up when I look in the console after I've try to run the db.activity.findOne(); from the cli session...
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-256, userName='totallyLegitUser', source='mfg-plan', password=<hidden>, mechanismProperties=<hidden>} com.mongodb.MongoCommandException: Command failed with error 17 (ProtocolError): 'Attempt to switch database target during SASL authentication.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Attempt to switch database target during SASL authentication.", "code": 17, "codeName": "ProtocolError"}
I have confirmed that the username, password, and database are all correct.
How do I get IntelliJ to connect to my authenticating mongos?
Problem solved. In the "Data Sources and Drivers" dialog for my mongo hosts it asks for a Database. I was giving it the database I wanted to connect to on the host (mfg-plan). What it wants is the authenticationDatabase for the host (usually 'admin'). When I change that to 'admin', all is well.

Cannot deploy war to GlassFish 4.1.2 server because database can't be found

I'm working through a book on GlassFish4 application server and have trouble deploying a sample war to the server. The server says:
"Error occurred during deployment: Exception while deploying the app [jpaintro-1.0] : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: The connection was refused because the database customerdb was not found. Error Code: 0. Please see server.log for more details."
The database server is Derby that comes with GlassFish. The database was created with this from the ./ij prompt:
connect 'jdbc:derby://localhost:1527/customerdb;create=true';
Next I could logon:
connect 'jdbc:derby://localhost:1527/customerdb;user=dev;password=dev';
and successfully enter table creation data and insert table data. Next I could retrieve this data with SQL. All fine, so the database exists.
Physical location database:
/home/fedora/GlassFish/glassfish4/glassfish/databases/1527/customerdb
The DERBY_HOME environment value was set.
I had to set up the following resources from the command line prompt:
./asadmin create-jdbc-connection-pool --datasourceclassname org.apache.derby.jdbc.ClientDataSource --restype javax.sql.DataSource --property DatabaseName=customerdb:User=dev:password=dev CustomerDBPool
./asadmin create-jdbc-resource --connectionpoolid CustomerDBPool jdbc/__CustomerDBPool
And I could verify in the GlassFish console that they were created successfully. The JDBC connection pool does indeed have an entry CustomerDBPool with an "additional property" name=DatabaseName, value=customerdb as well as user/password dev/dev. Also in the console is a JDBC resource with JNDI name jdbc/__CustomerDBPool and pool name CustomerDBPool
The war-file that I can't deploy contains a JPA-entity Customer and CDI named bean JpaDemoBean. The latter constructs a few Customer object and persists them to the database.
In the persistence.xml there is merely a jta-data-source element with value jdbc/__CustomerDBPool
I am all following literally "from the book".
Now why can't I deploy the war?
And all of a sudden I can't connect to the database via command line tool ij either:
ERROR 08004: The connection was refused because the database customerdb was not found.
I can stop and start the database server from the command line, but during startup I get the message:
"Invalid database home directory: /home/fedora/GlassFish/glassfish4/glassfish/databases"
Nevertheless the startup process continues and says it started the database successfully.
Thanks in advance!

MongoDB error "not authorised on admin"

I know this is a very common question for MongoDB, but I really tried most of the answers, but could not solve this issue.
So I feel I'm missing something Somewhere
Here are the steps:
Downloaded latest version 3.03 of MongoDB.
Custom installed to f:\MEAN\MongoDB.
F:\MEAN>sc.exe create MongoDBSvc binPath= "\"F:\mean\mongodb
\bin\mongod.exe\" -- service --config=\"F:\MEAN\MongoDBData\log\1.cfg\""
DisplayName= "MongoDBSvc" start= "auto"
[SC] CreateService SUCCESS
F:\MEAN>net start MongoDbSvc
The MongoDBSvc service is starting.
The MongoDBSvc service was started successfully.
F:\MEAN>mongo
MongoDB shell version: 3.0.3 connecting to: test
> view dbs
2015-05-28T14:00:10.907+1000 E QUERY SyntaxError: Unexpected identifier
> show dbs
2015-05-28T14:00:21.886+1000 E QUERY Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases:
1.0 }",
"code" : 13
}
at Error (<anonymous>)
at Mongo.getDBs (src/mongo/shell/mongo.js:47:15)
at shellHelper.show (src/mongo/shell/utils.js:630:33)
at shellHelper (src/mongo/shell/utils.js:524:36)
at (shellhelp2):1:1 at src/mongo/shell/mongo.js:47
> ^C
bye

Can't Connect to MongoDB from play app with salat: command failed [listDatabases]

I am trying to get started with the salat plugin in playframework. I have configured the database in application.conf and added all the dependencies to Build.scala and added salat to the play.plugins file. I haven't actually added any code to the project yet, I just followed the instructions on the github page, and then tried to run the project. I am getting the following error message
(Server started, use Ctrl+D to stop and go back to the console...)
[info] play - mongodb [default] connected at heroku_app4620908#ds031907.mongolab.com:31907/heroku_app4620908
[error] application -
! #6bchnaacn - Internal server error, for request [GET /] ->
play.api.Configuration$$anon$1: Configuration error [couldn't connect to [ds031907.mongolab.com/107.21.153.211:31907]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:71) ~[play_2.9.1-2.0.3.jar:2.0.3]
at play.api.Configuration.reportError(Configuration.scala:258) ~[play_2.9.1-2.0.3.jar:2.0.3]
at se.radley.plugin.salat.SalatPlugin$$anonfun$onStart$1.apply(SalatPlugin.scala:105) ~[play-plugins-salat_2.9.1-1.0.8.jar:1.0.8]
at se.radley.plugin.salat.SalatPlugin$$anonfun$onStart$1.apply(SalatPlugin.scala:98) ~[play-plugins-salat_2.9.1-1.0.8.jar:1.0.8]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194) ~[scala-library.jar:0.11.3]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194) ~[scala-library.jar:0.11.3]
Caused by: com.mongodb.CommandResult$CommandFailure: command failed [listDatabases]: { "serverUsed" : "db-uri" , "errmsg" : "need to login" , "ok" : 0.0}
at com.mongodb.CommandResult.getException(CommandResult.java:88) ~[mongo-java-driver-2.8.0.jar:na
at com.mongodb.CommandResult.throwOnError(CommandResult.java:134) ~[mongo-java-driver-2.8.0.jar:na]
at com.mongodb.Mongo.getDatabaseNames(Mongo.java:356) ~[mongo-java-driver-2.8.0.jar:na]
at com.mongodb.casbah.MongoConnection.getDatabaseNames(MongoConnection.scala:190) ~[casbah-core_2.9.1-2.4.1.jar:2.4.1]
at se.radley.plugin.salat.SalatPlugin$$anonfun$onStart$1.apply(SalatPlugin.scala:103) ~[play-plugins-salat_2.9.1-1.0.8.jar:1.0.8]
at se.radley.plugin.salat.SalatPlugin$$anonfun$onStart$1.apply(SalatPlugin.scala:98) ~[play-plugins-salat_2.9.1-1.0.8.jar:1.0.8]
I am stumped because I added my password and everything to the conf file. From the log it looks as though whatever is trying to connect to the database for me, is not logging in first, using the info I provided.
As you say, it looks like the root issue is that MongoDB is rejecting the command "listDatabases". This command requires administrator access to the MongoDB process since it reveals information about the other databases hosted there.
Unfortunately, the message it returns, "need to login", is a little misleading. You have logged in! You just don't have permission to list the databases.
Here's a simple experiment you can try yourself with the MongoDB shell. See that "show dbs" fails with the same error message you got in your app, but "show collections", which doesn't require access to any other databases outside your own, succeeds?
% mongo ds031907.mongolab.com:31907/heroku_app4620908 -u heroku_app4620908 -p your_password
MongoDB shell version: 2.0.7
connecting to: ds031907.mongolab.com:31907/heroku_app4620908
> show dbs
Fri Aug 17 13:12:10 uncaught exception: listDatabases failed:{ "errmsg" : "need to login", "ok" : 0 }
> show collections
system.indexes
system.users
(Note: I did this with my own MongoLab account and modified the text when copying and pasting here so you could just copy it into your terminal.)
Is there a way to avoid making the listDatabases call? I'm not familiar with the framework you're using.
I've the problem as well...
it should come with the SalatPlugin's onStart method that is requesting all database names: source._2.connection.getDatabaseNames().
This code is just testing the aliveness of the server...
I'm gonna check with leon how we could this differently! Sadly, you won't be able to connect until this will be fixed!
Stay tuned on this issue https://github.com/leon/play-salat/issues/23
This is fixed in the latest version of play-salat, it now uses getCollectionNames instead
use admin
db.addUser('userName', 'userPassword')
db.auth('userName', 'userPassword')
show dbs
java:
DB db = mongo.getDB("YouDBName") ;
db.authenticate("userName", "userPassword".toCharArray()) ;
System.out.println(mongo.getDatabaseNames()) ;