GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
BSON_OID_T(3) libbson BSON_OID_T(3)

BSON ObjectID Abstraction

#include <bson/bson.h>
typedef struct {

uint8_t bytes[12]; } bson_oid_t;


The bson_oid_t structure contains the 12-byte ObjectId notation defined by the BSON ObjectID specification.

ObjectId is a 12-byte BSON type, constructed using:

  • a 4-byte value representing the seconds since the Unix epoch (in Big Endian).
  • a 5-byte random value.
  • a 3-byte counter (Big Endian), starting with a random value.

You can convert an Object ID to a string using bson_oid_to_string() and back with bson_oid_init_from_string().

A bson_oid_t can be used in hashtables using the function bson_oid_hash() and bson_oid_equal().

A bson_oid_t can be compared to another using bson_oid_compare() for qsort() style comparing and bson_oid_equal() for direct equality.

You can validate that a string containing a hex-encoded ObjectID is valid using the function bson_oid_is_valid().

#include <bson/bson.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{

bson_oid_t oid;
char str[25];
bson_oid_init (&oid, NULL);
bson_oid_to_string (&oid, str);
printf ("%s\n", str);
if (bson_oid_is_valid (str, sizeof str)) {
bson_oid_init_from_string (&oid, str);
}
printf ("The UNIX time was: %u\n", (unsigned) bson_oid_get_time_t (&oid));
return 0; }


MongoDB, Inc

2009-present, MongoDB, Inc.

July 3, 2025 1.30.4

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.