str_to_oid#

langchain_mongodb.utils.str_to_oid(str_repr: str) β†’ Any | str[source]#

Attempt to cast string representation of id to MongoDB’s internal BSON ObjectId.

To be consistent with ObjectId, input must be a 24 character hex string. If it is not, MongoDB will happily use the string in the main _id index. Importantly, the str representation that comes out of MongoDB will have this form.

Parameters:

str_repr (str) – id as string.

Returns:

ObjectID

Return type:

Any | str