using MongoDB.Bson; ObjectId id = ObjectId.GenerateNewId();
ObjectId id = ObjectId.GenerateNewId(); string idString = id.ToString();
ObjectId id1 = ObjectId.GenerateNewId(); ObjectId id2 = ObjectId.GenerateNewId(); if (id1.CompareTo(id2) > 0) { Console.WriteLine("id1 is greater than id2"); } else if (id1.CompareTo(id2) < 0) { Console.WriteLine("id1 is less than id2"); } else { Console.WriteLine("id1 and id2 are equal"); }This code compares two ObjectIds and prints out whether they are greater than, less than, or equal to each other. Package library: MongoDB.Bson.