I am in the process of evaluating MongoDB and writing some basic PHP applications around it. Typically in my PHP/MySQL applications, I would create an ID field and set it to auto-increment on each row insert. I would then use this ID to relate to/join tables together.
However in MongoDB, there is no auto-increment (unless you create function to do it, I believe), only an objectID. Because of this, i'm unsure of how to relate collections together.
Is it worth writing an auto-increment function (as explained here: http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/), or is it common practice to store the ObjectID?
An example would be the following MySQL query:
SELECT * FROM cars WHERE car_type = '2'
But in MongoDB....
db.cars.find( { car_type : 507c35dd8fada716c89d0013 } );
Is the above standard practice? Am I using Mongo incorrectly by creating an auto-increment field?
Darius
EDIT: I think I am so deeply rooted in MySQL that I can't imagine an application without auto-incrementing IDs. Is it safe to store objectIDs (just as you would store a MySQL AI ID)? Is this bad for readability, since you would have to look up that objectID just to see what it relates to?
ObjectId("5889ff55736a51703194b3ce").getTimestamp()
returnsISODate("2017-01-26T13:53:25Z")
, of course it is not exactly an auto increment id but it is ordered already (I don't know what happens if server time changes)