how to use elasticsearch grails plugins with mongodb? - mongodb

I am using both elasticsearch plugins and mongodb plugins in my grails project.
The application.yml file is like:
mongodb:
host: "localhost"
port: 27017
databaseName: "search"
elasticSearch:
client:
mode: local
disableAutoIndex: false
datastoreImpl: mongoDatastore
bulkIndexOnStartup: true
index:
store.type: mmapfs
I commented out the hibernate in build.grdle because I need to use mongodb as your primary datastore.
//compile "org.grails.plugins:hibernate4"
Then the mongodb worked well since I could use
MyDomain.findByXXXXX()
to query the data in my mongodb.
But when I used
def result = MyDomain.search("${query}")
or
def result = elasticSearchService.search("${query}")
and print the result, it showed
[total:0, searchResults:[]]
That seemed the elasticSearch plugins worked but it did not connect to the mongodb.I wonder whether datastoreImpl: mongoDatastore worked or not.
Is there something I am missing? Appreciate your help in advance.
Thank You

Related

Setting MongoDB connection with Airflow

According to Astronomer docs here:
Despite this, I'm still not quite sure how to structure the JSON in Extras for this. I've tried:
{ uri: mongodb+srv://myuser:mypass#my-cluster.dwxnd.gcp.mongodb.net/mydb?retryWrites=true&w=majority } in the Extras but that doesn't work:
It seems like this should be obvious, yet I am struggling. What's the correct way, using our MongoDB URI from MongoDB Atlas, to create this connection in Airflow?
This setup worked for me in MongoDB Atlas. Extra part is important as it adds mongodb+srv to the final connection URI. Make sure you have provider package installed (http://airflow.apache.org/docs/apache-airflow-providers-mongo/stable/index.html).
Conn Id: mongo_connection
Conn Type: MongoDB
Host: cluster0.mtfak.mongodb.net
Schema: MyDatabaseName
Login: myuser
Password: mypass
Port: empty
Extra: {"srv": true}
This is what I would try:
Conn Type: mongodb+srv (or mongodb)
Host:my-cluster.blahlah.mongodb.net,
Login: <username>, Password: <password>.
Schema: admin (or your authDB)
The JSON object is as simple as this
{ retryWrite:true,
<field>:value,
w:majority
}

Using MongoDB in Symfony Monolog Causes Error

The error I'm getting is like the following:
Some information that you should know:
I'm using Symfony 5
I'm able to connect to mongo db using MongoDB Compass and in terminal using mongo command
What packages I have installed are the following:
"mongodb/mongodb": "^1.6"
"monolog/monolog": "^2.0"
"symfony/monolog-bundle": "^3.5"
My configuration file monolog.yaml (config/packages/dev/monolog.yaml) is like the following:
monolog:
handlers:
mongo:
type: mongo
mongo:
host: localhost
Thank you.
I had installed mongodb with brew. And I figured out MongoDB\Client class was not recognized. Then I found that we can install mongo driver manually.
I followed the steps here : https://www.php.net/manual/en/mongodb.installation.manual.php
I've changed my monolog configuration file monolog.yaml as
monolog:
handlers:
mongodb:
type: mongo
mongo:
id: mongolog
I added MongoDB\Client as service into service configuration file services.yaml
services:
...
mongolog:
class: MongoDB\Client
And after doing things above, it's worked.

Error configuring multiples mongodb servers in Symfony 2.8

I already have my app ( Symfony 2.8) hosted in Heroku. I have a mongoDB plugin to store session and it's working fine but when I try to add a replica server I face some problems. Replica is providaded by default for mongodb plugin. I mean
I am going to explain my environment and configuration:
ENV
I want to use this url ( it's which mongodb plugin provide me in Heroku)
MONGOLAB_URI = "mongodb://heroku_user:heroku_password#ds245975-a0.mlab.com:45975,ds245975-a1.mlab.com:45975/heroku_3b4l8zhl?replicaSet=rs-ds245975"
If I use this one is working:
MONGOLAB_URI = mongodb://heroku_user:heroku_password#ds245975-a0.mlab.com:45975/heroku_3b4l8zhl
CONF
In parameters.php I get this info:
$mongoLabUri = getenv('MONGOLAB_URI');
$mongoLabUri = getenv('MONGOLAB_URI');
if (false !== $mongoLabUri) {
$matches = [];
preg_match(
'#mongodb://(?P<user>.*?):(?P<password>.*?)#(?P<server>.*)/(?P<database>[^?]*)#',
$mongoLabUri,
$matches
);
$container->setParameter('mongo_server', 'mongodb://'.$matches['user'].':'.$matches['password'].'#'.$matches['server']."/".$matches['database']);
$container->setParameter('mongo_database', $matches['database']);
}
And in the configuration file, I configured the session handler to work with below parameters:
config.yml
doctrine_mongodb:
connections:
default:
server: %mongo_server%
options: {}
default_database: %mongo_database%
document_managers:
default:
auto_mapping: true
services:
session.handler.mongo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler
arguments: [#mongo, %mongo.session.options%]
mongo.connection:
class: MongoDoctrine\MongoDB\Connection
factory_service: doctrine.odm.mongodb.document_manager
factory_method: getConnection
calls:
- [initialize, []]
mongo:
class: Mongo
factory_service: mongo.connection
factory_method: getMongo
parameters:
mongo.session.options:
database: %mongo_database%
collection: session
Things that I tried
Configured the mongo_server with ?replicaSet=rs-ds245975
Remove ?replicaSet=rs-ds245975
I connect from mongo console to both server and it works.
Modified symfony configuration:
-https://symfony.com/doc/current/doctrine/mongodb_session_storage.html
-https://symfony.com/doc/master/bundles/DoctrineMongoDBBundle/config.html
Anything is working. I face different problem when I try to set the replica. It seems that there are some misunderstood that right now I am not able to see.
Any help/tip is welcome.
I need to modified the configuration of doctrine_mongodb in this way:
doctrine_mongodb:
connections:
default:
server: %mongo_server%
options:
connect: true
replicaSet: true
slaveOkay: true
default_database: %mongo_database%
document_managers:
default:
auto_mapping: true
And now is working

cant use .native function in sails mongo

I've been working around some ways to use .native() to do a simple aggregation function in sails with mongo.
Already following the steps to install dependencies. (http://sailsjs.org/documentation/reference/waterline-orm/models/native)
But still it returns me this error : .native is not a function
Did I missed something ?
You may be using the wrong adapter. You can check this in your models.js in the connection key. It might be commented out, if it is, it's going to connect to to local disk. Check that in connections.js, the name of your object that has mongodb config is named the same as models.js. eg.
connections.js
mongoServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
database: 'dbname'
}
models.js
connection: 'mongoServer'

Cakephp 2.3 baking with mongodb datasource

I try to use "./cake bake" to configure my db (mongo) and my models.
When I digit the command on my shell, my output is:
Welcome to CakePHP v2.3.2 Console
App : app
Path: /var/www/cakephp/app/
Interactive Bake Shell
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)
D
Database Configuration:
Name:
[default] >
Datasource: (Mysql/Postgres/Sqlite/Sqlserver)
Where are mongoDB's drivers?
Try taking a look at this github repo.
It will allow you to use MongoDB as a datastore for Cake