New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MongoDB integration #1438
MongoDB integration #1438
Conversation
It's some problem with script, because my script is working and I can connect to the database easily. |
Well the only real difference is that the yii ext uses MOngoClient and you use Mongo which is deprecated. Can you try using MOngoClient a sec? |
Also can you look in the log and tell us what the dsn is there, it should log the dsn just before opening the connection: https://github.com/yiisoft/yii2/blob/master/extensions/yii/mongodb/Connection.php#L226 |
and also I've inserted echo $this->dsn to make sure if dsn is right and it is good. |
found, problem was because of adding database name to dsn 'mongodb' => [
'class' => '\yii\mongodb\Connection',
'dsn' => 'mongodb://admin:PASSWORD@localhost:27017',
'defaultDatabaseName' => 'pgate'
], |
Also, Will you add functionality for auto incremental ids? |
You mean: http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/ ? It goes against the fundamentals of MongoDB and lowers performance drastically and builds lock on distributed envos, hence why MongoDB does not do AI IDs so it is up to @klimov-paul if he wants to add it, personally I have no intention of adding such a thing to Yii2. MongoDB should be used without AI IDs |
That it didn't work in the dsn like that might mean there might be a problem with the regexing of the database name from the dsn cos it should be fine to add the db name to the dsn: http://www.php.net/manual/en/mongoclient.construct.php so it might be that it isn't picking out the right database from the regex |
Because when I want to show smth by id (page.php?id=ID) echo Html::a('<i class="glyphicon glyphicon-remove-circle"></i>', ['/domains/delete', 'id' => (string) $domain['id']]); |
Yeah this is a known little thing, personally I work around it, besides you shouldn't need to do explicit casting, the url manager should able to cast it naturally, should. One thing you can do is maybe make your own custom smaller id, but not an AI ID, something random like the ObjectID but not so hard to make. |
For a similar issue with elasticsearch I use redis to generate my IDs: http://redis.io/commands/incr |
With elastic search I use the Hex of ObjectIDs works quite well |
But yeah redis is one that is used here |
I've found method to get |
That's not what it sounds like, thats the inc of the ObjectId and is definitely not unique and infact will rarely inc unless you are throwing many ops per second. |
This needs to be a good way of solving this problem which will be used by all users of Yii |
Distributed envos are really not designed for AI IDs, trust me it is really really realllllllly hard to ensure one |
I know, but (string) prefix is not right way too. |
It is actually, the ObjectId is perfect for distributed envos, not so good for sharding but it is still awesome |
And what about relations $this->hasOne(Modules::className(), ['_id' => 'module_id']); ? |
Relations should be fully catered to MongoId (ObjectId), last I looked at this extension. |
but they are not working |
Hmm I will need to have a look at that, if not then that should be considered a bug since ObjectId is default primary key for MongoDB. I will try and test as soon as I have a free moment. |
Oh, It was my fault, they are working. |
Ok kool :) |
Does MongoDB AR support caching? Yii::$app->getDb()->beginCache();
$model = Post::find($id)->one();
Yii::$app->getDb()->endCache(); And when It will be transaction support? |
No.
MongoDb server itself does not provide transaction support, so this extension simply have no change to introduce it. |
Will it have support caching? Oh, okey, thanks |
Though it is possible to implement client powered transactions which may be a further extension for someone to make. |
Relates to #11
Here is a MongoDB integration.
Note: I can not name myself an expert in MongoDB, so it could be I have forgotten or misplaced something, it would be nice if someone experienced with MongoDB review this PR.
Suggestions and critics are welcome.