colinmollenhour / mongodb-php-odm

A simple but powerful set of wrappers for using MongoDb in PHP (also a Kohana 3 module)
BSD 3-Clause "New" or "Revised" License
208 stars 50 forks source link

How to ensureindex for custom keys? #17

Closed ghost closed 13 years ago

ghost commented 13 years ago

Hey Colin, thanks for the great module. Been testing it so far and was about to transfer my mysql db over. Sorta got stumped at the ensureIndex() part. How do I implement this for custom document keys? Also, is there any way to access the native driver methods while using your module? Like batchInsert() etc. ?

colinmollenhour commented 13 years ago

You can use the native driver methods by simply calling them, they are proxied to MongoCursor or MongoCollection via the __call magic method.

As for creating indexes, you can insert into the system indexes collection: http://www.mongodb.org/display/DOCS/Index-Related+Commands

ghost commented 13 years ago

Hey Colin, I was just about done reading __call when I got your reply! I'm just curious why we can't map the native driver's ensureIndex as well? It's available in the MongoCollection class...

colinmollenhour commented 13 years ago

Yes, either way will work.

ghost commented 13 years ago

Thanks