diff --git a/executor_test.go b/executor_test.go index 556cd0b..f27e93d 100644 --- a/executor_test.go +++ b/executor_test.go @@ -1890,3 +1890,19 @@ func TestDistinctNumericValues(t *testing.T) { require.NotNil(t, result) require.Equal(t, 3, result.RowCount) // 100, 85, 90 } + +func TestCursorCountDeprecated(t *testing.T) { + client, cleanup := setupTestContainer(t) + defer cleanup() + + ctx := context.Background() + + gc := gomongo.NewClient(client) + + // cursor.count() is deprecated and should return an error + _, err := gc.Execute(ctx, "testdb", "db.users.find().count()") + require.Error(t, err) + require.Contains(t, err.Error(), "count()") + require.Contains(t, err.Error(), "countDocuments()") + require.Contains(t, err.Error(), "estimatedDocumentCount()") +} diff --git a/translator.go b/translator.go index ae5f433..3a9a5a9 100644 --- a/translator.go +++ b/translator.go @@ -608,6 +608,12 @@ func (v *mongoShellVisitor) visitMethodCall(ctx mongodb.IMethodCallContext) { case "distinct": v.operation.opType = opDistinct v.extractDistinctArgs(gmCtx) + case "count": + // cursor.count() is deprecated + v.err = &UnsupportedOperationError{ + Operation: "count()", + Hint: "MongoDB drivers deprecate their respective cursor and collection count() APIs in favor of countDocuments() and estimatedDocumentCount()", + } default: v.err = &UnsupportedOperationError{ Operation: methodName,