# ObjectId

An ObjectID class is available to scripts in order to facilitate working with BSON object ids used to represent unique identifiers.

**ObjectId(string/date/number)**\
Takes a hex string representation of an object id, a date or a timestamp in milliseconds.

Run this script

```
return {
    date: new ObjectID(new Date()),
    dateDate: new ObjectID(new Date()).toDate(),
    id: new ObjectID(),
    idDate: new ObjectID().toDate(),
    str: new ObjectID("4a232bca18759fcbdef24855"),
    strDate: new ObjectID("4a232bca18759fcbdef24855").toDate(),
    ts: new ObjectID("4a232bca18759fcbdef24855").getTimestamp()
}
```

And you might get this

```
{
    "date": "56d615040000000000000000",
    "dateDate": "2016-03-01T22:17:40.000Z",
    "id": "56d615048cacf5d0013e9305",
    "idDate": "2016-03-01T22:17:40.000Z",
    "str": "4a232bca18759fcbdef24855",
    "strDate": "2009-06-01T01:15:54.000Z",
    "ts": 1243818954
}
```

**id.toString()** returns the BSON id as a hexstring

**id.toJSON()**\
Used primarily by JSON.stringify(), returns the BSON id as a hexstring.

**id.equals(other)**\
Returns true if the passed in argument contains the same value as the id. The argument may be a hexstring or an ObjectID instance.

**id.toDate()**\
Returns the time the ObjectID was create as a Date value.

**id.getTimestamp()**\
Returns the number of seconds between midnight of January 1, 1970 and the time the ObjectID was created.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/scripting/objectid.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
