Skip to content
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

Merged
merged 56 commits into from Dec 5, 2013
Merged

MongoDB integration #1438

merged 56 commits into from Dec 5, 2013

Conversation

klimov-paul
Copy link
Member

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.

@asofter
Copy link

asofter commented Dec 19, 2013

It's some problem with script, because my script is working and I can connect to the database easily.

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

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?

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

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

@asofter
Copy link

asofter commented Dec 19, 2013

and also I've inserted echo $this->dsn to make sure if dsn is right and it is good.

@asofter
Copy link

asofter commented Dec 19, 2013

found, problem was because of adding database name to dsn

        'mongodb' => [
            'class' => '\yii\mongodb\Connection',
            'dsn' => 'mongodb://admin:PASSWORD@localhost:27017',
            'defaultDatabaseName' => 'pgate'
        ],

@asofter
Copy link

asofter commented Dec 19, 2013

Also, Will you add functionality for auto incremental ids?

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

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

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

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

@asofter
Copy link

asofter commented Dec 19, 2013

Because when I want to show smth by id (page.php?id=ID)
I need to change _id to string

echo Html::a('<i class="glyphicon glyphicon-remove-circle"></i>', ['/domains/delete', 'id' => (string) $domain['id']]);

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

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.

@cebe
Copy link
Member

cebe commented Dec 19, 2013

For a similar issue with elasticsearch I use redis to generate my IDs: http://redis.io/commands/incr
I use redis as cache anyway so I have that option. This is only in cases where users see the id.

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

With elastic search I use the Hex of ObjectIDs works quite well

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

But yeah redis is one that is used here

@asofter
Copy link

asofter commented Dec 19, 2013

I've found method to get

http://www.php.net/manual/en/mongoid.getinc.php

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

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.

@asofter
Copy link

asofter commented Dec 19, 2013

This needs to be a good way of solving this problem which will be used by all users of Yii

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

Distributed envos are really not designed for AI IDs, trust me it is really really realllllllly hard to ensure one

@asofter
Copy link

asofter commented Dec 19, 2013

I know, but (string) prefix is not right way too.

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

It is actually, the ObjectId is perfect for distributed envos, not so good for sharding but it is still awesome

@asofter
Copy link

asofter commented Dec 19, 2013

And what about relations $this->hasOne(Modules::className(), ['_id' => 'module_id']); ?

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

Relations should be fully catered to MongoId (ObjectId), last I looked at this extension.

@asofter
Copy link

asofter commented Dec 19, 2013

but they are not working

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

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.

@asofter
Copy link

asofter commented Dec 19, 2013

Oh, It was my fault, they are working.

@Sammaye
Copy link

Sammaye commented Dec 19, 2013

Ok kool :)

@klimov-paul klimov-paul deleted the mongo branch December 26, 2013 15:40
@asofter
Copy link

asofter commented Jan 11, 2014

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?

@klimov-paul
Copy link
Member Author

Does MongoDB AR support caching?

No.

And when It will be transaction support?

MongoDb server itself does not provide transaction support, so this extension simply have no change to introduce it.

@asofter
Copy link

asofter commented Jan 11, 2014

Will it have support caching?

Oh, okey, thanks

@Sammaye
Copy link

Sammaye commented Jan 11, 2014

Though it is possible to implement client powered transactions which may be a further extension for someone to make.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants