What i am trying to do is to connect mongodb atlas with my codeigniter framework.
I have used this library for mongodb
https://github.com/verkhoumov/codeigniter-mongodb-library
Below is my connection code
$config['mongo_db']['default'] = [
'settings' => [
'auth' => TRUE,
'debug' => TRUE,
'return_as' => 'array',
'auto_reset_query' => TRUE
],
'connection_string' => '',
'connection' => [
'host' => 'host link',
'port' => '27017',
'user_name' => 'username',
'user_password' => 'password',
'db_name' => 'dbname',
'db_options' => []
],
'driver' => []
];
The main problem is mongodb atlas doesnt provide you the port its query string is like mongodb+srv not mongodb:27017
MongoDb Atlas provides a connection string.
You can find it under Clusters -> Connect Your Application -> Copy a connection string.
Make sure to change "test" with your database name.
Then set it in 'connection_string' in your config file. Other parameters keep default.
$config['mongo_db']['default'] = [
'settings' => [
'auth' => TRUE,
'debug' => TRUE,
'return_as' => 'array',
'auto_reset_query' => TRUE
],
'connection_string' => 'mongodb://************#cluster0-shard-00-00-5ehze.gcp.mongodb.net:27017,cluster0-shard-00-01-5ehze.gcp.mongodb.net:27017,cluster0-shard-00-02-5ehze.gcp.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true',
'connection' => [
'host' => '',
'port' => '',
'user_name' => '',
'user_password' => '',
'db_name' => '',
'db_options' => []
],
'driver' => []
];
Related
I have created the Product's custom attributes programmatically(Setup->Installdata.php).
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'serial_code_use_customer',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Issue By Customer Group',
'input' => 'boolean',
'class' => '',
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
'group' => self::GROUP_LABEL,
'sort_order' => 3,
'note' => 'Enable automatic issuing of codes based on customer group.'
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'serial_code_customer_groups',
[
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => 'Select Customer Groups',
'input' => 'multiselect',
'class' => '',
'source' => \Magento\Customer\Model\Customer\Attribute\Source\Group::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
'group' => self::GROUP_LABEL,
'sort_order' => 4,
'note' => 'Customers in selected groups will be issued codes automatically when product is ordered.'
]
);
I want to Hide or Show a Custom attribute based on other custom attributes in the Product detail/edit page from Adminpanel Magento 2.4.x?
For example, there is a toggle on click (yes/no) the Customer Groups will be Hide / Show.
To hide custom product attributes from the admin product detail page you need to create UpgradeData.php in the My/Catalog/Setup directory.
Code:
$eavSetup->updateAttribute(Product::ENTITY, $attrCode, 'is_visible',
'0');
I need to integrate Graylog packet. I found this 'https://github.com/hedii/laravel-gelf-logger'
This is my config file
config/logging.php
'default' => 'stack',
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'gelf'],
],
'gelf' => [
'driver' => 'custom',
'via' => \Hedii\LaravelGelfLogger\GelfLoggerFactory::class,
'processors' => [
\Hedii\LaravelGelfLogger\Processors\NullStringProcessor::class,
// another processor...
],
'level' => 'debug',
'name' => 'bms-admin',
'system_name' => null,
'transport' => 'udp',
'host' => '192.168.41.112',
'port' => '5141',
'path' => null,
'max_length' => null,
'context_prefix' => null,
'extra_prefix' => null,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
]
When Laravel logged something, I received
Its my first time use compose.io as my mongodb hosting.
I was trying to configure compose.io mongodb with Laravel but ended up this error:
ConnectionTimeoutException in Collection.php line 432:
No suitable servers found (`serverSelectionTryOnce` set)
I was using https://github.com/jenssegers/laravel-mongodb package to add mongodb support to Laravel.
My mongodb config:
'mongodb' => [
'driver' => 'mongodb',
'host' => ['aws-us-east-1-portal.25.dblayer.com:20020/admin', 'aws-us-east-1-portal.26.dblayer.com:20020/admin'],
'port' => env('MONGO_DB_PORT', 27017),
'database' => env('MONGO_DB_DATABASE'),
'username' => env('MONGO_DB_USERNAME'),
'password' => env('MONGO_DB_PASSWORD'),
'options' => [
'ssl' => true,
'database' => 'admin', // sets the authentication database required by mongo 3
'replicaSet' => 'set-5939226a8aab5300121d0ef2',
'readPreference' => 'primary',
],
'driver_options' => [
'context' => stream_context_create( [
'ssl' => [
'local_cert' => base_path('mongo.pem'),
'cafile' => base_path('mongo.pem'),
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
'verify_expiry' => false,
'allow_invalid_certificates' => true
]
])
]
]
I am not also sure what is the value for MONGO_REPLICA_SET
Anyone experienced something similar?
Thanks
It works by removing replicaSet option
Final configuration:
'mongodb' => [
'driver' => 'mongodb',
'host' => ['aws-us-east-1-portal.25.dblayer.com', 'aws-us-east-1-portal.26.dblayer.com'],
'port' => env('MONGO_DB_PORT', 27017),
'database' => env('MONGO_DB_DATABASE'),
'username' => env('MONGO_DB_USERNAME'),
'password' => env('MONGO_DB_PASSWORD'),
'options' => [
'ssl' => true,
'database' => env('MONGO_DB_DATABASE'), // sets the authentication database required by mongo 3
],
'driver_options' => [
'context' => stream_context_create( [
'ssl' => [
'cafile' => base_path('mongo.pem'),
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
'verify_expiry' => false,
]
])
]
]
This is what I have in common/config/main-local:
'mongodb' => [
'class' => 'yii\mongodb\Connection',
'dns' => 'mongodb://localhost:27017/test',
],
What's wrong with that?
Replace "localhost" to "127.0.0.1"
'mongodb' => [
'class' => '\yii\mongodb\Connection',
'dsn' => 'mongodb://127.0.0.1:27017/test',
],
There's a typo. It should be
'dsn' => 'mongodb://localhost:27017/test'
instead of
'dns' => 'mongodb://localhost:27017/test'
I am using ADmad/cakephp-jwt-auth plugin for Json web token authentication for rest api.
For the token generation we i am sending email and password to login via form . but it fails i don't what is issue.
Here is the my settings. in AppController.php
$this->loadComponent('Auth', [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
],
'authenticate' => [
'ADmad/JwtAuth.Jwt' => [
'parameter' => '_token',
'userModel' => 'Users',
'scope' => ['Users.active' => 1],
'fields' => [
'id' => 'id'
]
]
],
'unauthorizedRedirect' => false,
// Config below is available since CakePHP 3.1.
// It makes user info available in controller's beforeFilter() which is not possible in CakePHP 3.0.
'checkAuthIn' => 'Controller.initialize',
]);
UsersController Token generation method script;
public function token(){
$user = $this->Auth->identify();
if (!$user) {
throw new UnauthorizedException('Invalid email or password');
}
$this->set([
'success' => true,
'data' => [
'token' => $token = \JWT::encode([
'id' => $user['id'],
'exp' => time() + 604800
],
Security::salt())
],
'_serialize' => ['success', 'data']
]);
}
The json data i am posting is
{
'email' : 'muni#smart.com',
'password': '123'
}
Please say me what is mistake?
Form must be in the authenticate
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
],
'ADmad/JwtAuth.Jwt' => [
'parameter' => '_token',
'userModel' => 'Users',
'fields' => [
'id' => 'id'
]
]
]
]);