I using symfony2 with doctrine for my project.
How I can turn off prepare statement for every sql query?
I need it because, I use pgbouncer for PostgreSQL connect and prepare statement doesn't support.
You can use this:
doctrine:
dbal:
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
options:
20: true # PDO::ATTR_EMULATE_PREPARES
PDO::ATTR_EMULATE_PREPARES equals to 20, but the last time I checked, you weren't allowed to use it as a hash key, thus 20.
I am still searching for solution. But you can use native pg_connect() function
Related
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
}
I wish to have connected more than 1 users at the same time, as follows:
const massive = require('massive');
massive({
host: 'localhost',
port: 5432,
database: 'appdb',
user: 'user_1',
password: 'pwd_1',
ssl: false,
poolSize: 10
}).then(instance_1 => {...});
massive({
host: 'localhost',
port: 5432,
database: 'appdb',
user: 'user_2',
password: 'pwd_2',
ssl: false,
poolSize: 10
}).then(instance_2 => {...});
user_1 and user_2 obviously have different privileges.
So, my question is: in which way the two instances 1 and 2 are related?
In the beginning, I suspect they are identical. Later, do they get synchronized? Do I have to run db.reload()?
Tia
The short answer is that you don't have anything to worry about unless and until you make schema changes. If you do modify the schema at runtime you will need to call db.reload() from each instance to ensure that they're current. However, modifying the schema at runtime is an uncommon use case to say the least.
The two instances are completely independent and are never automatically synchronized. The database objects (tables, views, etc) that both users have access to will be identical until a change is made and one is reloaded.
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
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
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'