I make a "copy" of MySQL table in MongoDB for PHP application. And I have id column which is PRIMARY KEY. Should I store it in mongodb as:
['_id' => (string) $id]
or
['_id' => (int) $id]
or
['_id' => new \MongoId($id)]
or
['_id' => new \MongoId, 'id' => $id]
I don't plan on having more than one machine for mongodb or making a lot of queries by that ID alone.
What is the difference in using string, integer or ObjectId here?
All the above options would work. I personally like to leave _id
for mongodb to manage and so would go with the fourth option.
I would make an exception for the case where this collection could grow to a large size. In that case, I would go for the second option since that would consume the least space.