diff --git a/src/MongoDB.Driver/Core/Misc/Feature.cs b/src/MongoDB.Driver/Core/Misc/Feature.cs
index c3b6d249961..560162bdb92 100644
--- a/src/MongoDB.Driver/Core/Misc/Feature.cs
+++ b/src/MongoDB.Driver/Core/Misc/Feature.cs
@@ -52,6 +52,7 @@ public class Feature
private static readonly Feature __convertOperatorStringToObjectOrArray = new Feature("ConvertOperatorStringToObjectOrArray", WireVersion.Server83);
private static readonly Feature __createIndexCommitQuorum = new Feature("CreateIndexCommitQuorum", WireVersion.Server44);
private static readonly Feature __createIndexesUsingInsertOperations = new Feature("CreateIndexesUsingInsertOperations", WireVersion.Zero, WireVersion.Server42);
+ private static readonly Feature __createObjectIdExpression = new Feature("CreateObjectIdExpression", WireVersion.Server83);
private static readonly Feature __csfleRangeAlgorithm = new Feature("CsfleRangeAlgorithm", WireVersion.Server62);
private static readonly Feature __csfle2Qev2Lookup = new Feature("csfle2Qev2Lookup", WireVersion.Server81);
private static readonly Feature __csfle2Qev2RangeAlgorithm = new Feature("csfle2Qev2RangeAlgorithm", WireVersion.Server80);
@@ -248,6 +249,11 @@ public class Feature
[Obsolete("This feature was removed in server version 4.2. As such, this property will be removed in a later release.")]
public static Feature CreateIndexesUsingInsertOperations => __createIndexesUsingInsertOperations;
+ ///
+ /// Represents support for the $createObjectId operator feature.
+ ///
+ public static Feature CreateObjectIdExpression => __createObjectIdExpression;
+
///
/// Gets the csfle range algorithm feature.
///
diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstNodeType.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstNodeType.cs
index 48ddd2eb0a6..3af3b3af469 100644
--- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstNodeType.cs
+++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstNodeType.cs
@@ -38,6 +38,7 @@ internal enum AstNodeType
ConstantExpression,
ConvertExpression,
CountStage,
+ CreateObjectIdExpression,
CurrentOpStage,
CustomAccumulatorExpression,
DateAddExpression,
diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstCreateObjectIdExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstCreateObjectIdExpression.cs
new file mode 100644
index 00000000000..da128cf1961
--- /dev/null
+++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstCreateObjectIdExpression.cs
@@ -0,0 +1,30 @@
+/* Copyright 2010-present MongoDB Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using MongoDB.Bson;
+using MongoDB.Driver.Linq.Linq3Implementation.Ast.Visitors;
+
+namespace MongoDB.Driver.Linq.Linq3Implementation.Ast.Expressions;
+
+internal sealed class AstCreateObjectIdExpression : AstExpression
+{
+ public override AstNodeType NodeType => AstNodeType.CreateObjectIdExpression;
+
+ public override AstNode Accept(AstNodeVisitor visitor) =>
+ visitor.VisitCreateObjectIdExpression(this);
+
+ public override BsonValue Render() =>
+ new BsonDocument("$createObjectId", new BsonDocument());
+}
diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpression.cs
index ec9c44bf48e..8bbbbdb08b3 100644
--- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpression.cs
+++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpression.cs
@@ -443,6 +443,9 @@ public static AstExpression Floor(AstExpression arg)
return new AstUnaryExpression(AstUnaryOperator.Floor, arg);
}
+ public static AstCreateObjectIdExpression CreateObjectId()
+ => new();
+
public static AstGetFieldExpression GetField(AstExpression input, AstExpression fieldName)
{
return new AstGetFieldExpression(input, fieldName);
diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs
index 72e50374a1c..e2365532fac 100644
--- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs
+++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs
@@ -244,6 +244,9 @@ public virtual AstNode VisitCustomAccumulatorExpression(AstCustomAccumulatorExpr
return node.Update(VisitAndConvert(node.InitArgs), VisitAndConvert(node.AccumulateArgs));
}
+ public virtual AstNode VisitCreateObjectIdExpression(AstCreateObjectIdExpression node)
+ => node;
+
public virtual AstNode VisitDateAddExpression(AstDateAddExpression node)
{
return node.Update(VisitAndConvert(node.StartDate), VisitAndConvert(node.Unit), VisitAndConvert(node.Amount), VisitAndConvert(node.Timezone));
diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MqlMethod.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MqlMethod.cs
index 3a6265c5d5c..de5f41c6b4f 100644
--- a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MqlMethod.cs
+++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MqlMethod.cs
@@ -27,6 +27,7 @@ internal static class MqlMethod
private static readonly MethodInfo __constantWithRepresentation;
private static readonly MethodInfo __constantWithSerializer;
private static readonly MethodInfo __convert;
+ private static readonly MethodInfo __createObjectId;
private static readonly MethodInfo __dateFromString;
private static readonly MethodInfo __dateFromStringWithFormat;
private static readonly MethodInfo __dateFromStringWithFormatAndTimezone;
@@ -53,6 +54,7 @@ static MqlMethod()
__constantWithRepresentation = ReflectionInfo.Method((object value, BsonType representation) => Mql.Constant(value, representation));
__constantWithSerializer = ReflectionInfo.Method((object value, IBsonSerializer