Enviroment
mongoosastic version: 4.4.1
node version: 7.10.1
mongoose version: 4.11.7
elasticsearch version: 6.4.0
Expectation:
Post Model:
{ usernames : ["5ae2cf1dd18f412bcf522750", "5abc7852f28e0b50530af785", "5b582c6b9751c9672f77324d"] }
Usermodel :
[{_id : 5ae2cf1dd18f412bcf522750, username : "temp"}]
Need to join/map user in post
If a user search the name 'temp' respective post_id should be getting searched by elasticsearch
Actual Behaviour:
Currently unable to map/join
Thanks in advance
Related
I was using strap 3.0.0.next-11 and then migrated my APIs to 3.6.8 version.
In 3.6.8 i see this error in a pop-up , for collections which has relations:
An error occurred during models config fetch.
on logs i see this error :
Cast to ObjectId failed for value "http://54.179.156.135:1339/uploads/d26af51633f2451a934896bfc125ec90.jpg" at path "_id" for model "file"
Why is this happening on 3.6.8 ? I have been using the older version without any issues and with this new version I am unable to feth anything.
I am using following :
node : 14.17.6 (LTS)
npm : 6.14.15
strapi : 3.6.8
I have also attached the image of my package.json.
So I figured out the reason why this was happening in my case. After migrating to 3.6.8 , the fields in model which have type :
"thumbnail": {
"model": "file",
"via": "related",
"plugin": "upload"
}
need to have values stored as ObjectId in database as a reference to an entry in upload_file which is maintained by strapi internally.
earlier, thumbnail would store value as a string url ( url of the image ).
Example :
thumbnail : https://my_image_url_path/img.jpg
Now , thumbnail stores the reference i.e. ObjectId , which refers to an entry in the upload_file collection which is responsible for maintaining all the images uploaded via strapi upload api.
Example :
thumbnail : ObjectId("60f53bf69f811d268d8fedb1")
I am trying to connect from SERVER-1 to my mongo server which is running in some other sever SERVER-2
So my grails app is running in SERVER-1. So I have given external configuration like this.
grails {
mongo {
host = "<SERVER-2>-host"
port = 27017
username = "myapp"
password = "myapp"
databaseName = "myapp"
options {
autoConnectRetry = true
connectTimeout = 3000
}
}
}
And in the SERVER-2 I've created myapp db and with the same user and credentials
use myapp
db.createUser( { "user" : "myapp",
"pwd": "myapp",
"roles" : [] },
{ w: "majority" , wtimeout: 5000 } )
And am able to see the users list like below
> db.getUsers()
[
{
"_id" : "myapp.myapp",
"user" : "myapp",
"db" : "myapp",
"roles" : [ ]
}
]
Mongo configuration contains "noauth=true",
And from SERVER-1, I'm able to connect to SERVER-2 mongo using the below command
mongo SERVER-2-HOST:27017/myapp -u myapp -p myapp
But when i try to connect from SERVER-1 grails application, its giving the below error
| Error Error executing script LoadVars: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [myapp], username = [myapp], password = [m***p]
My mongod.conf file
# mongod.conf
logpath=/var/log/mongodb/mongod.log
logappend=true
fork=true
#port=27017
dbpath=/var/lib/mongo
pidfilepath=/var/run/mongodb/mongod.pid
# Listen to local interface only. Comment out to listen on all interfaces.
#bind_ip=127.0.0.1
# nojournal=true
#cpu=true
#noauth=false
auth=true
Am I missing anything here?
Looks like your MongoDB server is running and listening properly but not able to authenticate.
The first problem I'm seeing is that, you mentioned your Grails application is running on 1st server while your MongoDB server is on the 2nd, but the host in your DataSource.groovy configuration is configured to connect to the 1st host, not the 2nd. Is that just in the example or your code is really connecting to the 1st server (which is wrong)? Please verify it.
The second problem might be with the way you are adding the user to the database name myapp. Please follow these steps and try again after connecting:
1) Login to MongoDB instance on the 2nd host: mongo
2) Use your database use myapp
3) Verify that you don not have any user named myapp by running db.dropUser("myapp")
4) Now add the user:
db.createUser({
user: "myapp",
pwd: "myapp",
roles: [ "readWrite", "dbAdmin" ]
});
Now connect your Grails application.
Update
If you are using MongoDB 3.x and Grails 2.5.x or 2.4.x then this should be the problem of your authentication failure. I almost forgot to tell you this problem.
Grails somehow shipping the older version of Java driver i.e. 2.12.3 and to support MongoDB 3, we require minimum 2.13.x of Java driver. Also, the 3.0 Java driver is not a required upgrade for MongoDB 3.0. The 2.13.0 release is the minimum required for full compatibility with MongoDB 3.0.
https://github.com/mongodb/mongo-java-driver/releases/tag/r3.0.0
So, in your BuildConfig.groovy add this as dependency:
dependencies {
compile "org.mongodb:mongo-java-driver:2.13.1"
}
Also, if you are using Grails mongeez plugin, exclude the java driver from there:
compile (":mongeez:0.2.3") {
excludes("mongo-java-driver")
}
I'll create a ticket for this in Grails. Hope this helps!
Creating database-specific authentic user:
1. Run mongod from cmd
2. Run mongo from cmd
3. use "your_db_name"
4.
db.createUser(
{
user: "anik",
pwd: "password",
roles: [ { role: "dbOwner", db: "your_db_name" } ]
}
)
Take note of the db name. Insert urs.
5. mongo "your_db_name" -u anik -p password
6. Switch to your collections bson folder
7. mongorestore -d ss "abc.bson"
After Authentication you can connect to db using username password from your project properties file.
I got the issue with my setup.
Actually I was using grails mongo version 3.0.0
and I installed MongoDB 3.0.0. So according to this grails mongo documentation, grails mongo 3.0.0 plugin supports only MongoDB 2.6. But I was using 3.0.0(upgraded version).
Check this.
https://github.com/grails/grails-data-mapping/issues/557
So now MongoDB 3.0 doesn't support SCRAM-SHA-1 authSchema. So we should use some other techniques to authenticate our user.
I managed to add my mongo data source under SpagoBi server (version 5.1) but I can't do it under SpagoBI studio(version 5.1) .
I can't find the mongoDB driver under the available list of jdbc driver in SpagoBI studio and when I tried to add it I got those exceptions:
I tried:
to add a new data source -> add a new connection profile -> I chose "generic jdbc"
In the driver class name I tried:
"mongodb.jdbc.MongoDriver" like mentionned in this thread [1]
but it gave me this exception :
java.lang.ClassNotFoundException: mongodb.jdbc.MongoDriver
I tried "com.mongodb.Mongo" and it gives me:
java.lang.ClassCastException: com.mongodb.Mongo cannot be cast to java.sql.Driver
How can I add my MongoDB as a new data source under SpagoBI Studio?
[1] what is the JDBC driver class name for mongodb?
MongoDB datasource with SpagoBI. All-In-One-SpagoBI-5.1.0_21012015 and installed the mongo-java-driver-3.0.0.jar
Following are the datasource configuration details :
Type: jdbc URL : server:port/database User : dbusername Pasword : dbpasword Driver: mongo
User driver name as mongo and place the mongo-java-driver-3.0.0.jar in lib folder
Just wondering if anyone has integrated spago and monogdb.
If so how did you approach this problems?
Any idea wil be much appreciated.
It worked at-last for me. MongoDB with SpagoBI.
All-In-One-SpagoBI-5.1.0_21012015 and installed the mongo-java-driver-3.0.0.jar
Following are the datasource configuration details :
Type: jdbc
URL : server:port/database
User : dbusername
Pasword : dbpasword
Driver: mongo
Details for dataset creation
http://wiki.spagobi.org/xwiki/bin/view/spagobi_server/data_set
I am calling the MongoDB aggregate function in my code as :
AggregationOutput output = collection.aggregate( matchUserID, unwindF, matchFUsers,projection);
I have tested my code in my localhost, and it works perfect. When I am using the same in another DB (version 2.2.1), it gives this error :
com.mongodb.CommandResult$CommandFailure: command failed [aggregate]: { "serverUsed" : "<server address>" , "errmsg" : "no such cmd: aggregate" , "bad cmd" : { "aggregate" : .... }
Any clue why ?
Based on other answers I've seen to similar questions, it seems most likely that the server is not actually 2.2.1 as you believe.
How are you checking the server's version number?
From the shell, try this:
use admin
db.runCommand( {buildInfo: 1} )
figured out the error. I was using the 2.9 version on the MongoDB Java driver. When I upgraded it to 2.10, it worked perfectly. Thanks folks :)
I had the same error "no such cmd: aggregate", and I tried new version of mongodb 2.4,2.6 from default debian repositories and always receiving this error.
After that installed mongodb-org-server from mongo repo and it worked
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/