The ObjectId class represents a MongoDB ObjectId.
More...
#include <QC_ObjectId.dox.h>
The ObjectId class represents a MongoDB ObjectId.
MongoDB ObjectIds are 12-byte identifiers typically used as the default value for the _id field in MongoDB documents. They consist of:
- 4 bytes representing seconds since Unix epoch
- 5 bytes of random value
- 3 bytes of incrementing counter
- Example:
ObjectId oid();
printf("New ObjectId: %s\n", oid.toString());
ObjectId oid2("507f1f77bcf86cd799439011");
date dt = oid.getTimestamp();
- Since
- mongodb 1.0
◆ compare()
| int mongodb::ObjectId::compare |
( |
ObjectId |
other | ) |
|
Compares this ObjectId to another.
- Code Flags:
- CONSTANT
- Parameters
-
- Returns
- -1 if this ObjectId is less than other, 0 if equal, 1 if greater
- Example:
int cmp = oid1.compare(oid2);
◆ constructor() [1/2]
| mongodb::ObjectId::constructor |
( |
| ) |
|
Creates a new ObjectId with a generated value.
- Example:
-
◆ constructor() [2/2]
| mongodb::ObjectId::constructor |
( |
string |
hex_string | ) |
|
Creates an ObjectId from a 24-character hex string.
- Parameters
-
| hex_string | the 24-character hexadecimal string representation of the ObjectId |
- Example:
ObjectId oid("507f1f77bcf86cd799439011");
- Exceptions
-
| MONGODB-OBJECTID-ERROR | the hex string is not a valid ObjectId |
◆ copy()
| mongodb::ObjectId::copy |
( |
| ) |
|
Creates a copy of the ObjectId.
- Example:
ObjectId oid2 = oid.copy();
◆ equals()
| bool mongodb::ObjectId::equals |
( |
ObjectId |
other | ) |
|
Checks if this ObjectId equals another.
- Code Flags:
- CONSTANT
- Parameters
-
- Returns
- True if the ObjectIds are equal
- Example:
if (oid1.equals(oid2)) {
print("Same ObjectId\n");
}
◆ getTimestamp()
| date mongodb::ObjectId::getTimestamp |
( |
| ) |
|
Returns the timestamp portion of the ObjectId as a date/time value.
- Returns
- the timestamp when the ObjectId was created
- Code Flags:
- CONSTANT
- Example:
date dt = oid.getTimestamp();
◆ hashCode()
| int mongodb::ObjectId::hashCode |
( |
| ) |
|
Returns a hash code for this ObjectId.
- Returns
- the hash code
- Code Flags:
- CONSTANT
- Example:
-
◆ toString()
| string mongodb::ObjectId::toString |
( |
| ) |
|
Returns the ObjectId as a 24-character hexadecimal string.
- Returns
- the hexadecimal string representation
- Code Flags:
- CONSTANT
- Example:
string str = oid.toString();
The documentation for this class was generated from the following file: