For instance...


I'm able to str() it...but...

How do i find up by string?

Edit: I would like each document in Mongo to possess a unique identifier (often a string) will be able to look on. I had been wishing the item ID might be this (because it provides extensive letter and it is unique.) And That I would like it to use HTTP GET. view?uid=e93jfsb0e3jflskdjf

You are able to create a new ObjectId while using string. This situation uses the MongoDB console:

db.users.find({ _id: ObjectId("4cdfb11e1f3c000000007822") })

I can not tell out of your question which language driver you're using (if any whatsoever), but many motorists also support this functionality.

You shouldn't convert the ObjectId within the database to some string, after which compare it to a different string. If you would do that, MongoDB cannot make use of the _id index and will also need to scan all of the documents, leading to poor query performance.

For your questions:

Could it be ok to make use of Mongo's “Object ID” since it's unique identifier?

Yes, it's intended for this function. Making unique IDs could be a discomfort in sharded conditions, so MongoDB performs this for you personally.

If that's the case, how do i convert it to some string and appear up by string?

Don't. It isn't a string. MongoDB really allows you override the default ID. If you start trying to find #"4cdfb11e1f3c000000007822", Mongo thinks that you are searching for a string. If rather you search for ObjectId("4cdfb11e1f3c000000007822"), Mongo will search for the ObjectId (or MongoID).

Inside your question, it appears like you are attempting to pass it in like a string. The way you convert this for an "objectid" will rely on your driver. PHP includes a MongoId. Other motorists have the identical function.