# str_to_oid

> **Function** in `langchain_mongodb`

📖 [View in docs](https://reference.langchain.com/python/langchain-mongodb/utils/str_to_oid)

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.

## Signature

```python
str_to_oid(
    str_repr: str,
) -> Any | str
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `str_repr` | `str` | Yes | id as string. |

## Returns

`Any | str`

ObjectID

---

[View source on GitHub](https://github.com/langchain-ai/langchain-mongodb/blob/ad9050c28e092b335dcb846f77c0ec2245553f79/libs/langchain-mongodb/langchain_mongodb/utils.py#L141)