Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(mongodb): migrate parser from ANTLR to omni (#19839)
h3n4lc444a84341c0
diff --git a/backend/plugin/parser/mongodb/completion.go b/backend/plugin/parser/mongodb/completion.goindex d1b05a1472..0c6732dbfc 100644--- a/backend/plugin/parser/mongodb/completion.go+++ b/backend/plugin/parser/mongodb/completion.go@@ -6,227 +6,48 @@ import ("slices""strings"- "github.com/antlr4-go/antlr/v4"- parser "github.com/bytebase/parser/mongodb"+ "github.com/bytebase/omni/mongo/catalog"+ omnicompletion "github.com/bytebase/omni/mongo/completion"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/parser/base"- "github.com/bytebase/bytebase/backend/store/model")// validIdentifierRegexp matches valid JavaScript identifiers that can be used with dot notation.-// Valid identifiers: start with letter/underscore/$, contain only letters/digits/underscore/$.var validIdentifierRegexp = regexp.MustCompile(`^[a-zA-Z_$][a-zA-Z0-9_$]*$`)-var globalFollowSetsByState = base.NewFollowSetsByState()-func init() {base.RegisterCompleteFunc(storepb.Engine_MONGODB, Completion)}-func newIgnoredTokens() map[int]bool {- return map[int]bool{- antlr.TokenEOF: true,- parser.MongoShellLexerLPAREN: true,- parser.MongoShellLexerRPAREN: true,- parser.MongoShellLexerLBRACE: true,- parser.MongoShellLexerRBRACE: true,- parser.MongoShellLexerLBRACKET: true,- parser.MongoShellLexerRBRACKET: true,- parser.MongoShellLexerCOLON: true,- parser.MongoShellLexerCOMMA: true,- parser.MongoShellLexerSEMI: true,- parser.MongoShellLexerDOLLAR: true,- parser.MongoShellLexerNUMBER: true,- parser.MongoShellLexerDOUBLE_QUOTED_STRING: true,- parser.MongoShellLexerSINGLE_QUOTED_STRING: true,- parser.MongoShellLexerIDENTIFIER: true,- parser.MongoShellLexerREGEX_LITERAL: true,- }-}--func newPreferredRules() map[int]bool {- return map[int]bool{- parser.MongoShellParserRULE_collectionAccess: true,- }-}--func newNoSeparatorRequired() map[int]bool {- return map[int]bool{- parser.MongoShellLexerLPAREN: true,- parser.MongoShellLexerRPAREN: true,- parser.MongoShellLexerLBRACE: true,- parser.MongoShellLexerRBRACE: true,- parser.MongoShellLexerLBRACKET: true,- parser.MongoShellLexerRBRACKET: true,- parser.MongoShellLexerCOLON: true,- parser.MongoShellLexerCOMMA: true,- parser.MongoShellLexerDOT: true,- parser.MongoShellLexerSEMI: true,- }-}--// Completer provides MongoDB-specific code completion.-type Completer struct {- ctx context.Context- core *base.CodeCompletionCore- parser *parser.MongoShellParser- lexer *parser.MongoShellLexer- scanner *base.Scanner- instanceID string- defaultDatabase string- getMetadata base.GetDatabaseMetadataFunc- listDatabaseNames base.ListDatabaseNamesFunc- metadataCache map[string]*model.DatabaseMetadata- noSeparatorRequired map[int]bool-}--// NewCompleter creates a new MongoDB completer.-func NewCompleter(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) *Completer {- input := antlr.NewInputStream(statement)- lexer := parser.NewMongoShellLexer(input)- stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)- p := parser.NewMongoShellParser(stream)- p.RemoveErrorListeners()- lexer.RemoveErrorListeners()-- scanner := base.NewScanner(stream, true)- scanner.SeekPosition(caretLine, caretOffset)- scanner.Push()-- core := base.NewCodeCompletionCore(- ctx,- p,- newIgnoredTokens(),- newPreferredRules(),- &globalFollowSetsByState,- -1, // No query rule for MongoDB- -1, // No shadow query rule- -1, // No select item alias rule- -1, // No CTE rule- )-- return &Completer{- ctx: ctx,- core: core,- parser: p,- lexer: lexer,- scanner: scanner,- instanceID: cCtx.InstanceID,- defaultDatabase: cCtx.DefaultDatabase,- getMetadata: cCtx.Metadata,- listDatabaseNames: cCtx.ListDatabaseNames,- metadataCache: make(map[string]*model.DatabaseMetadata),- noSeparatorRequired: newNoSeparatorRequired(),- }-}--// previousNonDotToken returns the token type of the previous non-DOT token,-// skipping hidden tokens. Used to determine if the caret follows a method-// call (RPAREN) or a collection access (identifier/RBRACKET).-func (c *Completer) previousNonDotToken() int {- c.scanner.Push()- defer c.scanner.PopAndRestore()-- for c.scanner.Backward(true) {- t := c.scanner.GetTokenType()- if t != parser.MongoShellLexerDOT {- return t- }- }- return antlr.TokenEOF-}--// listCollections returns collection names from the default database.-func (c *Completer) listCollections() []string {- if c.defaultDatabase == "" {- return nil- }-- if _, exists := c.metadataCache[c.defaultDatabase]; !exists {- if c.getMetadata == nil {- return nil- }- _, metadata, err := c.getMetadata(c.ctx, c.instanceID, c.defaultDatabase)- if err != nil || metadata == nil {- return nil- }- c.metadataCache[c.defaultDatabase] = metadata- }-- metadata := c.metadataCache[c.defaultDatabase]- var collections []string- for _, schema := range metadata.ListSchemaNames() {- schemaMeta := metadata.GetSchemaMetadata(schema)- if schemaMeta == nil {- continue- }- collections = append(collections, schemaMeta.ListTableNames()...)- }- slices.Sort(collections)- return collections-}--// complete performs the actual completion.-func (c *Completer) complete() ([]base.Candidate, error) {- caretIndex := c.scanner.GetIndex()- if caretIndex > 0 && !c.noSeparatorRequired[c.scanner.GetPreviousTokenType(false)] {- caretIndex--- }+// Completion is the entry point for MongoDB code completion.+func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) ([]base.Candidate, error) {+ // Build omni catalog from Bytebase metadata.+ cat := buildCatalog(ctx, cCtx)- c.parser.Reset()- ctx := c.parser.Program()+ // Convert caret line:column to byte offset.+ byteOffset := caretToByteOffset(statement, caretLine, caretOffset)- candidates := c.core.CollectCandidates(caretIndex, ctx)+ // Get omni completion candidates.+ candidates := omnicompletion.Complete(statement, byteOffset, cat)- return c.convertCandidates(candidates)-}+ // Detect whether cursor is inside bracket notation (db[|).+ inBracket := isAfterOpenBracket(statement, byteOffset)-// convertCandidates converts ANTLR C3 candidates to completion candidates.-// It uses C3 preferred rules to determine context:-// - RULE_collectionAccess: after "db." or "db[" — suggest database methods + collections-//-// C3 tokens are used in all positions. At the database level (db.|), the collectionAccess-// preferred rule prevents C3 from exploring into methodChain, so only legitimate db method-// tokens appear. At collection/cursor level, C3 tokens provide the correct method candidates.-func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]base.Candidate, error) {+ // Convert to base.Candidate, formatting collection names for context.var result []base.Candidate-- _, hasCollectionAccess := candidates.Rules[parser.MongoShellParserRULE_collectionAccess]-- // Convert C3 token candidates to function candidates.- // All tokens at any position are methods, so treat them as functions with "()" suffix.- result = append(result, c.getTokenCandidates(candidates)...)-- if hasCollectionAccess {- // At db.| or db[ position — also add collection candidates from metadata.- prevToken := c.previousNonDotToken()- switch prevToken {- case parser.MongoShellLexerLBRACKET:- for _, collection := range c.listCollections() {- result = append(result, base.Candidate{- Type: base.CandidateTypeTable,- Text: formatBracketContent(collection),- })- }- default:- for _, collection := range c.listCollections() {- if needsBracketNotation(collection) {- result = append(result, base.Candidate{- Type: base.CandidateTypeTable,- Text: formatBracketNotation(collection),- })- } else {- result = append(result, base.Candidate{- Type: base.CandidateTypeTable,- Text: collection,- })- }- }+ for _, c := range candidates {+ text := c.Text+ if c.Type == omnicompletion.CandidateCollection {+ text = formatCollectionCandidate(c.Text, inBracket)}+ result = append(result, base.Candidate{+ Type: omniCandidateTypeToBase(c.Type),+ Text: text,+ })}- // Sort and deduplicate+ // Sort and deduplicate.slices.SortFunc(result, func(a, b base.Candidate) int {if a.Type != b.Type {if a.Type < b.Type {@@ -248,56 +69,100 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]}), nil}-// getTokenCandidates converts C3 token candidates to function candidates.-func (c *Completer) getTokenCandidates(candidates *base.CandidatesCollection) []base.Candidate {- var result []base.Candidate- for token := range candidates.Tokens {- if token < 0 || token >= len(c.lexer.LiteralNames) {- continue- }- literal := c.lexer.LiteralNames[token]- if literal == "" {+// buildCatalog creates an omni catalog from Bytebase completion context.+func buildCatalog(ctx context.Context, cCtx base.CompletionContext) *catalog.Catalog {+ cat := catalog.New()++ if cCtx.DefaultDatabase == "" || cCtx.Metadata == nil {+ return cat+ }++ _, metadata, err := cCtx.Metadata(ctx, cCtx.InstanceID, cCtx.DefaultDatabase)+ if err != nil || metadata == nil {+ return cat+ }++ for _, schema := range metadata.ListSchemaNames() {+ schemaMeta := metadata.GetSchemaMetadata(schema)+ if schemaMeta == nil {continue}- text := strings.Trim(literal, "'")- if text == "" {- continue+ for _, table := range schemaMeta.ListTableNames() {+ cat.AddCollection(table)}- result = append(result, base.Candidate{- Type: base.CandidateTypeFunction,- Text: text + "()",- })}- return result++ return cat}-// needsBracketNotation returns true if the collection name contains special characters-// that require bracket notation (db["name"]) instead of dot notation (db.name).-func needsBracketNotation(name string) bool {- return !validIdentifierRegexp.MatchString(name)+// caretToByteOffset converts a 1-based line and 0-based column offset to a byte offset.+// Note: caretOffset is treated as a rune (code point) offset, not UTF-16 code units.+// This matches the existing behavior of the completion callers in this codebase.+func caretToByteOffset(statement string, caretLine int, caretOffset int) int {+ line := 1+ col := 0+ for i, r := range statement {+ if line == caretLine && col == caretOffset {+ return i+ }+ if r == '\n' {+ line+++ col = 0+ } else {+ col+++ }+ }+ return len(statement)}-// formatBracketNotation formats a collection name for bracket notation access.-// It escapes double quotes and backslashes in the name.-// Used when suggesting after "db." - inserts full ["name"] syntax.-func formatBracketNotation(name string) string {- // Escape backslashes first, then double quotes- escaped := strings.ReplaceAll(name, `\`, `\\`)- escaped = strings.ReplaceAll(escaped, `"`, `\"`)- return `["` + escaped + `"]`+// isAfterOpenBracket checks if the cursor position is inside bracket notation (db[|).+func isAfterOpenBracket(statement string, byteOffset int) bool {+ // Scan backwards from cursor to find the nearest unmatched '['.+ for i := byteOffset - 1; i >= 0; i-- {+ switch statement[i] {+ case '[':+ return true+ case ']', '\n', ';':+ return false+ }+ }+ return false}-// formatBracketContent formats a collection name for insertion inside brackets.-// Used when user typed "db[" - inserts "name"] to complete the bracket.-func formatBracketContent(name string) string {- // Escape backslashes first, then double quotes- escaped := strings.ReplaceAll(name, `\`, `\\`)- escaped = strings.ReplaceAll(escaped, `"`, `\"`)- return `"` + escaped + `"]`+// formatCollectionCandidate formats a collection name for completion context.+// In bracket context (db[|): returns "name"] to complete the bracket expression.+// In dot context (db.|): returns bracket notation ["name"] for special chars, bare name otherwise.+func formatCollectionCandidate(name string, inBracket bool) string {+ if inBracket {+ escaped := strings.ReplaceAll(name, `\`, `\\`)+ escaped = strings.ReplaceAll(escaped, `"`, `\"`)+ return `"` + escaped + `"]`+ }+ if !validIdentifierRegexp.MatchString(name) {+ escaped := strings.ReplaceAll(name, `\`, `\\`)+ escaped = strings.ReplaceAll(escaped, `"`, `\"`)+ return `["` + escaped + `"]`+ }+ return name}-// Completion is the entry point for MongoDB code completion.-func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) ([]base.Candidate, error) {- completer := NewCompleter(ctx, cCtx, statement, caretLine, caretOffset)- return completer.complete()+// omniCandidateTypeToBase maps omni completion candidate types to Bytebase base types.+func omniCandidateTypeToBase(t omnicompletion.CandidateType) base.CandidateType {+ switch t {+ case omnicompletion.CandidateCollection:+ return base.CandidateTypeTable+ case omnicompletion.CandidateKeyword, omnicompletion.CandidateShowTarget:+ return base.CandidateTypeKeyword+ case omnicompletion.CandidateMethod,+ omnicompletion.CandidateCursorMethod,+ omnicompletion.CandidateAggStage,+ omnicompletion.CandidateQueryOperator,+ omnicompletion.CandidateBSONHelper,+ omnicompletion.CandidateDbMethod,+ omnicompletion.CandidateRsMethod,+ omnicompletion.CandidateShMethod:+ return base.CandidateTypeFunction+ default:+ return base.CandidateTypeFunction+ }}diff --git a/backend/plugin/parser/mongodb/diagnose.go b/backend/plugin/parser/mongodb/diagnose.goindex 851d7feba6..a59b27b416 100644--- a/backend/plugin/parser/mongodb/diagnose.go+++ b/backend/plugin/parser/mongodb/diagnose.go@@ -12,18 +12,21 @@ func init() {}// Diagnose performs syntax checking on a MongoDB shell script.+// Uses best-effort parsing to report all syntax errors, not just the first one.func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]base.Diagnostic, error) {- diagnostics := []base.Diagnostic{}+ _, parseErrors := ParseMongoShellBestEffort(statement)- raw := parseMongoShellRaw(statement)- if raw == nil {- return diagnostics, nil- }-- for _, err := range raw.Errors {- if err != nil {- diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(err, statement))+ var diagnostics []base.Diagnostic+ for _, parseErr := range parseErrors {+ syntaxErr := &base.SyntaxError{+ Position: &storepb.Position{+ Line: int32(parseErr.Line),+ Column: int32(parseErr.Column),+ },+ RawMessage: parseErr.Message,+ Message: parseErr.Message,}+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxErr, statement))}return diagnostics, nildiff --git a/backend/plugin/parser/mongodb/masking.go b/backend/plugin/parser/mongodb/masking.goindex 7d4e479d84..ccd2401164 100644--- a/backend/plugin/parser/mongodb/masking.go+++ b/backend/plugin/parser/mongodb/masking.go@@ -2,12 +2,8 @@ package mongodbimport ("slices"- "strconv"- "strings"- "github.com/antlr4-go/antlr/v4"- mongoparser "github.com/bytebase/parser/mongodb"- "github.com/pkg/errors"+ "github.com/bytebase/omni/mongo/analysis""github.com/bytebase/bytebase/backend/plugin/parser/base")@@ -31,476 +27,67 @@ const (// AnalyzeMaskingStatement analyzes a MongoDB shell statement for masking checks.// It returns nil,nil for statements that are not relevant to masking flow.func AnalyzeMaskingStatement(statement string) (*MaskingAnalysis, error) {- raw := parseMongoShellRaw(statement)- if raw == nil || raw.Tree == nil {- return nil, nil- }- if len(raw.Errors) > 0 {- return nil, errors.Errorf("failed to parse MongoDB statement: %s", raw.Errors[0].Message)+ stmts, err := ParseMongoShell(statement)+ if err != nil {+ return nil, err}-- if len(raw.Tree.AllStatement()) != 1 {+ if len(stmts) != 1 {return nil, nil}- listener := &maskingAnalysisListener{}- antlr.ParseTreeWalkerDefault.Walk(listener, raw.Tree)- if listener.analysis == nil {+ node, ok := GetOmniNode(stmts[0].AST)+ if !ok || node == nil {return nil, nil}- return listener.analysis, nil-}--type maskingAnalysisListener struct {- *mongoparser.BaseMongoShellParserListener-- analysis *MaskingAnalysis-}--func (l *maskingAnalysisListener) EnterCollectionOperation(ctx *mongoparser.CollectionOperationContext) {- if l.analysis != nil {- return- }-- collection := extractCollectionName(ctx.CollectionAccess())- if collection == "" {- return- }-- chain := ctx.MethodChain()- if chain == nil {- return- }- mc := chain.CollectionMethodCall()- if mc == nil {- return- }-- analysis := classifyMaskingMethod(mc)- if analysis == nil {- return- }- analysis.Collection = collection- if len(analysis.PredicateFields) > 0 {- slices.Sort(analysis.PredicateFields)- }- l.analysis = analysis-}--func classifyMaskingMethod(mc mongoparser.ICollectionMethodCallContext) *MaskingAnalysis {- switch {- case mc.FindMethod() != nil:- return &MaskingAnalysis{- API: MaskableAPIFind,- Operation: "find",- PredicateFields: extractFindPredicateFields(mc.FindMethod().Arguments()),- }- case mc.FindOneMethod() != nil:- return &MaskingAnalysis{- API: MaskableAPIFindOne,- Operation: "findOne",- PredicateFields: extractFindPredicateFields(mc.FindOneMethod().Arguments()),- }- case mc.CountDocumentsMethod() != nil:- return unsupportedReadAnalysis("countDocuments")- case mc.EstimatedDocumentCountMethod() != nil:- return unsupportedReadAnalysis("estimatedDocumentCount")- case mc.CollectionCountMethod() != nil:- return unsupportedReadAnalysis("count")- case mc.DistinctMethod() != nil:- return unsupportedReadAnalysis("distinct")- case mc.AggregateMethod() != nil:- return classifyAggregateForMasking(mc.AggregateMethod())- case mc.GetIndexesMethod() != nil:- return unsupportedReadAnalysis("getIndexes")- case mc.StatsMethod() != nil:- return unsupportedReadAnalysis("stats")- case mc.StorageSizeMethod() != nil:- return unsupportedReadAnalysis("storageSize")- case mc.TotalIndexSizeMethod() != nil:- return unsupportedReadAnalysis("totalIndexSize")- case mc.TotalSizeMethod() != nil:- return unsupportedReadAnalysis("totalSize")- case mc.DataSizeMethod() != nil:- return unsupportedReadAnalysis("dataSize")- case mc.IsCappedMethod() != nil:- return unsupportedReadAnalysis("isCapped")- case mc.ValidateMethod() != nil:- return unsupportedReadAnalysis("validate")- case mc.LatencyStatsMethod() != nil:- return unsupportedReadAnalysis("latencyStats")- case mc.GetShardDistributionMethod() != nil:- return unsupportedReadAnalysis("getShardDistribution")- case mc.GetShardVersionMethod() != nil:- return unsupportedReadAnalysis("getShardVersion")- case mc.AnalyzeShardKeyMethod() != nil:- return unsupportedReadAnalysis("analyzeShardKey")- default:- return nil- }-}--func unsupportedReadAnalysis(operation string) *MaskingAnalysis {- return &MaskingAnalysis{- API: MaskableAPIUnsupportedRead,- Operation: operation,- }-}--func extractCollectionName(access mongoparser.ICollectionAccessContext) string {- switch access := access.(type) {- case *mongoparser.DotAccessContext:- if id := access.Identifier(); id != nil {- return id.GetText()- }- case *mongoparser.BracketAccessContext:- if sl := access.StringLiteral(); sl != nil {- return unquoteMongoString(sl.GetText())- }- case *mongoparser.GetCollectionAccessContext:- if sl := access.StringLiteral(); sl != nil {- return unquoteMongoString(sl.GetText())- }- default:- }- return ""-}--func unquoteMongoString(s string) string {- if s == "" {- return ""- }- if unquoted, err := strconv.Unquote(s); err == nil {- return unquoted- }- return strings.Trim(s, `"'`)-}--func extractFindPredicateFields(args mongoparser.IArgumentsContext) []string {- if args == nil {- return nil- }- allArgs := args.AllArgument()- if len(allArgs) == 0 {- return nil- }-- first := allArgs[0]- if first == nil || first.Value() == nil {- return nil- }-- doc := extractDocumentValue(first.Value())- if doc == nil {- return nil- }-- fields := make(map[string]struct{})- collectPredicateFieldsFromDocument(doc, "", fields)- if len(fields) == 0 {- return nil- }-- result := make([]string, 0, len(fields))- for field := range fields {- result = append(result, field)- }- return result-}--func extractDocumentValue(value mongoparser.IValueContext) mongoparser.IDocumentContext {- if value == nil {- return nil- }- switch value := value.(type) {- case *mongoparser.DocumentValueContext:- return value.Document()- default:- return nil- }-}--func extractArrayValue(value mongoparser.IValueContext) mongoparser.IArrayContext {- if value == nil {- return nil- }- switch value := value.(type) {- case *mongoparser.ArrayValueContext:- return value.Array()- default:- return nil- }-}--func collectPredicateFieldsFromDocument(doc mongoparser.IDocumentContext, prefix string, fields map[string]struct{}) {- if doc == nil {- return- }- for _, pair := range doc.AllPair() {- collectPredicateFieldsFromPair(pair, prefix, fields)- }-}-func collectPredicateFieldsFromPair(pair mongoparser.IPairContext, prefix string, fields map[string]struct{}) {- if pair == nil || pair.Key() == nil {- return- }-- key := extractPairKey(pair.Key())- if key == "" {- return- }-- if strings.HasPrefix(key, "$") {- collectLogicalPredicateFieldsByKey(key, pair.Value(), prefix, fields)- return- }-- fullPath := buildPredicateFieldPath(prefix, key)- fields[fullPath] = struct{}{}- collectPredicateFieldValue(pair.Value(), fullPath, fields)-}--func collectLogicalPredicateFieldsByKey(key string, value mongoparser.IValueContext, prefix string, fields map[string]struct{}) {- if !isLogicalOperator(key) {- return- }- collectLogicalOperatorValue(value, prefix, fields)-}--func buildPredicateFieldPath(prefix, key string) string {- if prefix == "" {- return key+ a := analysis.Analyze(node)+ if a == nil {+ return nil, nil}- return prefix + "." + key-}-func collectPredicateFieldValue(value mongoparser.IValueContext, fullPath string, fields map[string]struct{}) {- if childDoc := extractDocumentValue(value); childDoc != nil {- collectPredicateFieldsFromDocument(childDoc, fullPath, fields)- return- }- if childArr := extractArrayValue(value); childArr != nil {- collectPredicateFieldsFromArray(childArr, fullPath, fields)- }+ return omniAnalysisToMasking(a)}-func collectPredicateFieldsFromArray(arr mongoparser.IArrayContext, prefix string, fields map[string]struct{}) {- if arr == nil {- return- }- for _, v := range arr.AllValue() {- if childDoc := extractDocumentValue(v); childDoc != nil {- collectPredicateFieldsFromDocument(childDoc, prefix, fields)- }+// omniAnalysisToMasking converts an omni StatementAnalysis to a MaskingAnalysis.+// Returns nil,nil for non-read operations (not relevant to masking).+func omniAnalysisToMasking(a *analysis.StatementAnalysis) (*MaskingAnalysis, error) {+ if !a.Operation.IsRead() {+ return nil, nil}-}-func collectLogicalOperatorValue(value mongoparser.IValueContext, prefix string, fields map[string]struct{}) {- if value == nil {- return- }- if doc := extractDocumentValue(value); doc != nil {- collectPredicateFieldsFromDocument(doc, prefix, fields)- return+ result := &MaskingAnalysis{+ Operation: a.MethodName,+ Collection: a.Collection,}- if arr := extractArrayValue(value); arr != nil {- collectPredicateFieldsFromArray(arr, prefix, fields)- }-}-func extractPairKey(keyCtx mongoparser.IKeyContext) string {- switch keyCtx := keyCtx.(type) {- case *mongoparser.UnquotedKeyContext:- if id := keyCtx.Identifier(); id != nil {- return id.GetText()+ switch a.Operation {+ case analysis.OpFind:+ result.API = MaskableAPIFind+ result.PredicateFields = a.PredicateFields+ case analysis.OpFindOne:+ result.API = MaskableAPIFindOne+ result.PredicateFields = a.PredicateFields+ case analysis.OpAggregate:+ if a.UnsupportedStage != "" {+ result.API = MaskableAPIUnsupportedRead+ result.UnsupportedStage = a.UnsupportedStage+ return result, nil}- case *mongoparser.QuotedKeyContext:- if sl := keyCtx.StringLiteral(); sl != nil {- return unquoteMongoString(sl.GetText())+ result.API = MaskableAPIAggregate+ result.PredicateFields = a.PredicateFields+ for _, join := range a.Joins {+ result.JoinedCollections = append(result.JoinedCollections, JoinedCollection{+ Collection: join.Collection,+ AsField: join.AsField,+ })}default:+ result.API = MaskableAPIUnsupportedRead}- if keyCtx == nil {- return ""- }- return keyCtx.GetText()-}-func isLogicalOperator(key string) bool {- switch key {- case "$and", "$or", "$nor":- return true- default:- return false+ if len(result.PredicateFields) > 0 {+ slices.Sort(result.PredicateFields)}-}--// shapePreservingAggregateStages contains aggregate pipeline stages whose output-// documents retain the collection's original structure (fields are not reshaped).-var shapePreservingAggregateStages = map[string]bool{- "$match": true,- "$sort": true,- "$limit": true,- "$skip": true,- "$sample": true,- "$addFields": true,- "$set": true,- "$unset": true,- "$geoNear": true,- "$setWindowFields": true,- "$fill": true,- "$redact": true,- "$unwind": true,-}-func classifyAggregateForMasking(am mongoparser.IAggregateMethodContext) *MaskingAnalysis {- predicateFields, joinedCollections, unsupportedStage := extractAggregatePredicateFields(am.Arguments())- if unsupportedStage != "" {- return &MaskingAnalysis{- API: MaskableAPIUnsupportedRead,- Operation: "aggregate",- UnsupportedStage: unsupportedStage,- }- }- return &MaskingAnalysis{- API: MaskableAPIAggregate,- Operation: "aggregate",- PredicateFields: predicateFields,- JoinedCollections: joinedCollections,- }-}--// extractAggregatePredicateFields walks the pipeline and returns:-// - predicate fields from $match stages-// - join info from $lookup/$graphLookup stages-// - the first unsupported stage name, or "" if all stages are allowed-func extractAggregatePredicateFields(args mongoparser.IArgumentsContext) ([]string, []JoinedCollection, string) {- if args == nil {- return nil, nil, ""- }- allArgs := args.AllArgument()- if len(allArgs) == 0 {- return nil, nil, ""- }-- first := allArgs[0]- if first == nil || first.Value() == nil {- return nil, nil, ""- }-- arr := extractArrayValue(first.Value())- if arr == nil {- return nil, nil, "unknown"- }-- fields := make(map[string]struct{})- var joinedCollections []JoinedCollection- for _, elem := range arr.AllValue() {- doc := extractDocumentValue(elem)- if doc == nil {- return nil, nil, "unknown"- }- pairs := doc.AllPair()- if len(pairs) == 0 {- continue- }- stageName := extractPairKey(pairs[0].Key())- switch {- case shapePreservingAggregateStages[stageName]:- if stageName == "$match" {- stageDoc := extractDocumentValue(pairs[0].Value())- if stageDoc != nil {- collectPredicateFieldsFromDocument(stageDoc, "", fields)- }- }- case stageName == "$lookup":- join, unsupported := extractLookupJoin(pairs[0].Value())- if unsupported {- return nil, nil, "$lookup"- }- if join != nil {- joinedCollections = append(joinedCollections, *join)- }- case stageName == "$graphLookup":- join := extractGraphLookupJoin(pairs[0].Value())- if join != nil {- joinedCollections = append(joinedCollections, *join)- }- default:- return nil, nil, stageName- }- }-- var predicateFields []string- if len(fields) > 0 {- predicateFields = make([]string, 0, len(fields))- for field := range fields {- predicateFields = append(predicateFields, field)- }- }- return predicateFields, joinedCollections, ""-}--// extractLookupJoin parses a $lookup stage value and returns the join info.-// Returns (nil, true) if this is a pipeline-form $lookup (unsupported).-// Returns (nil, false) if from/as cannot be extracted (treated as passthrough).-func extractLookupJoin(value mongoparser.IValueContext) (*JoinedCollection, bool) {- doc := extractDocumentValue(value)- if doc == nil {- return nil, false- }- var from, as string- for _, pair := range doc.AllPair() {- key := extractPairKey(pair.Key())- switch key {- case "pipeline":- // Pipeline form is not supported.- return nil, true- case "from":- from = extractStringLiteralValue(pair.Value())- case "as":- as = extractStringLiteralValue(pair.Value())- default:- }- }- if from == "" || as == "" {- return nil, false- }- return &JoinedCollection{AsField: as, Collection: from}, false-}--// extractGraphLookupJoin parses a $graphLookup stage value and returns the join info.-func extractGraphLookupJoin(value mongoparser.IValueContext) *JoinedCollection {- doc := extractDocumentValue(value)- if doc == nil {- return nil- }- var from, as string- for _, pair := range doc.AllPair() {- key := extractPairKey(pair.Key())- switch key {- case "from":- from = extractStringLiteralValue(pair.Value())- case "as":- as = extractStringLiteralValue(pair.Value())- default:- }- }- if from == "" || as == "" {- return nil- }- return &JoinedCollection{AsField: as, Collection: from}-}--// extractStringLiteralValue extracts a plain string value from a Value node.-func extractStringLiteralValue(value mongoparser.IValueContext) string {- if value == nil {- return ""- }- text := value.GetText()- if len(text) >= 2 && (text[0] == '"' || text[0] == '\'') {- return unquoteMongoString(text)- }- return ""+ return result, nil}diff --git a/backend/plugin/parser/mongodb/mongodb.go b/backend/plugin/parser/mongodb/mongodb.goindex 62baf3d29e..9b0bd2236c 100644--- a/backend/plugin/parser/mongodb/mongodb.go+++ b/backend/plugin/parser/mongodb/mongodb.go@@ -1,12 +1,12 @@-// Package mongodb provides MongoDB shell parser functionality for LSP features.package mongodbimport (- "github.com/antlr4-go/antlr/v4"+ "unicode/utf8"- "github.com/bytebase/parser/mongodb"+ "github.com/bytebase/omni/mongo"+ "github.com/bytebase/omni/mongo/ast"+ omniparser "github.com/bytebase/omni/mongo/parser"- "github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/parser/base")@@ -15,105 +15,102 @@ func init() {base.RegisterParseStatementsFunc(storepb.Engine_MONGODB, ParseMongoShell)}-// rawParseResult contains the raw result from ANTLR parsing.-// Used internally by Diagnose and statement_ranges which need raw ANTLR data.-type rawParseResult struct {- Tree mongodb.IProgramContext- Errors []*base.SyntaxError- Stream *antlr.CommonTokenStream+// OmniAST wraps an omni MongoDB AST node and implements the base.AST interface.+type OmniAST struct {+ Node ast.Node+ StartPosition *storepb.Position}-// parseMongoShellRaw performs the raw ANTLR parsing and returns the program tree,-// token stream, and any syntax errors.-func parseMongoShellRaw(statement string) *rawParseResult {- inputStream := antlr.NewInputStream(statement)- lexer := mongodb.NewMongoShellLexer(inputStream)- stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)- p := mongodb.NewMongoShellParser(stream)-- lexer.RemoveErrorListeners()- p.RemoveErrorListeners()- errorListener := mongodb.NewMongoShellErrorListener()- lexer.AddErrorListener(errorListener)- p.AddErrorListener(errorListener)-- tree := p.Program()+// ASTStartPosition implements base.AST.+func (a *OmniAST) ASTStartPosition() *storepb.Position {+ return a.StartPosition+}- result := &rawParseResult{- Tree: tree,- Stream: stream,+// GetOmniNode extracts the omni AST node from a base.AST interface.+func GetOmniNode(a base.AST) (ast.Node, bool) {+ if a == nil {+ return nil, false}-- for _, err := range errorListener.Errors {- result.Errors = append(result.Errors, &base.SyntaxError{- Position: &storepb.Position{- Line: int32(err.Line),- Column: int32(err.Column + 1),- },- RawMessage: err.Message,- Message: err.Message,- })+ omniAST, ok := a.(*OmniAST)+ if !ok {+ return nil, false}-- return result+ return omniAST.Node, true}// ParseMongoShell parses a MongoDB shell script and returns parsed statements// with their ASTs. Conforms to the standard ParseStatementsFunc interface.+//+// The omni parser recovers from syntax errors by skipping to the next statement+// boundary. When at least one statement parses successfully, this function+// returns the partial results with a nil error. A non-nil error is returned+// only when no statements could be parsed at all.func ParseMongoShell(statement string) ([]base.ParsedStatement, error) {- raw := parseMongoShellRaw(statement)- if raw.Tree == nil {- return nil, nil+ stmts, err := mongo.Parse(statement)+ if err != nil {+ return nil, err}+ return convertStatements(statement, stmts), nil+}- runes := []rune(statement)- var result []base.ParsedStatement+// ParseMongoShellBestEffort parses a MongoDB shell script and returns as many+// successfully parsed statements as possible, along with any parse errors.+// Used by LSP-facing functions where partial results are better than nothing.+func ParseMongoShellBestEffort(statement string) ([]base.ParsedStatement, []*omniparser.ParseError) {+ result := mongo.ParseBestEffort(statement)+ return convertStatements(statement, result.Statements), result.Errors+}- for _, stmt := range raw.Tree.AllStatement() {- if stmt == nil {- continue- }- start := stmt.GetStart()- stop := stmt.GetStop()- if start == nil || stop == nil {+func convertStatements(input string, stmts []mongo.Statement) []base.ParsedStatement {+ var result []base.ParsedStatement+ for _, stmt := range stmts {+ if stmt.Empty() {continue}-- startOffset := start.GetStart()- endOffset := min(stop.GetStop()+1, len(runes))-- text := string(runes[startOffset:endOffset])- byteStart := len(string(runes[:startOffset]))- byteEnd := len(string(runes[:endOffset]))-- ps := base.ParsedStatement{+ startPos := byteOffsetToPosition(input, stmt.ByteStart)+ endPos := byteOffsetToPosition(input, stmt.ByteEnd)+ result = append(result, base.ParsedStatement{Statement: base.Statement{- Text: text,- Start: &storepb.Position{- Line: int32(start.GetLine()),- Column: int32(start.GetColumn() + 1),- },- End: common.ConvertANTLRTokenToExclusiveEndPosition(- int32(stop.GetLine()),- int32(stop.GetColumn()),- stop.GetText(),- ),+ Text: stmt.Text,+ Start: startPos,+ End: endPos,Range: &storepb.Range{- Start: int32(byteStart),- End: int32(byteEnd),+ Start: int32(stmt.ByteStart),+ End: int32(stmt.ByteEnd),},},- AST: &base.ANTLRAST{- StartPosition: &storepb.Position{- Line: int32(start.GetLine()),- Column: int32(start.GetColumn() + 1),- },- Tree: stmt,- Tokens: raw.Stream,+ AST: &OmniAST{+ Node: stmt.AST,+ StartPosition: startPos,},+ })+ }+ return result+}++// byteOffsetToPosition converts a byte offset to a 1-based line:column position+// where column is measured in Unicode code points.+func byteOffsetToPosition(sql string, byteOffset int) *storepb.Position {+ if byteOffset > len(sql) {+ byteOffset = len(sql)+ }++ line := int32(1)+ runeCol := int32(0)+ i := 0+ for i < byteOffset {+ r, size := utf8.DecodeRuneInString(sql[i:])+ if r == '\n' {+ line+++ runeCol = 0+ } else {+ runeCol++}- result = append(result, ps)+ i += size}- return result, nil+ return &storepb.Position{+ Line: line,+ Column: runeCol + 1,+ }}diff --git a/backend/plugin/parser/mongodb/mongodb_test.go b/backend/plugin/parser/mongodb/mongodb_test.goindex 9617e3c6ce..5c2d34c788 100644--- a/backend/plugin/parser/mongodb/mongodb_test.go+++ b/backend/plugin/parser/mongodb/mongodb_test.go@@ -96,11 +96,9 @@ func TestParseMongoShell(t *testing.T) {}func TestParseMongoShellSyntaxError(t *testing.T) {- // Syntax errors are handled by parseMongoShellRaw, used by Diagnose.- // ParseMongoShell returns whatever statements the error recovery produces.- raw := parseMongoShellRaw(`db.collection.find({`)- require.NotNil(t, raw)- require.NotEmpty(t, raw.Errors, "expected errors")+ // Omni parser returns an error for invalid syntax.+ _, err := ParseMongoShell(`db.collection.find({`)+ require.Error(t, err, "expected parse error for unclosed brace")}func TestGetStatementRanges(t *testing.T) {diff --git a/backend/plugin/parser/mongodb/query_span_test.go b/backend/plugin/parser/mongodb/query_span_test.goindex 40e061581b..8852f92975 100644--- a/backend/plugin/parser/mongodb/query_span_test.go+++ b/backend/plugin/parser/mongodb/query_span_test.go@@ -117,7 +117,7 @@ func TestGetQuerySpan(t *testing.T) {wantType: base.DDL,},{- description: "find with explain is Explain",+ description: "find with explain suffix is Explain",statement: `db.users.find({}).explain()`,wantType: base.Explain,},diff --git a/backend/plugin/parser/mongodb/query_type.go b/backend/plugin/parser/mongodb/query_type.goindex aff22c7358..1136918bd6 100644--- a/backend/plugin/parser/mongodb/query_type.go+++ b/backend/plugin/parser/mongodb/query_type.go@@ -1,11 +1,9 @@package mongodbimport (- "strings"+ "slices"- "github.com/antlr4-go/antlr/v4"-- "github.com/bytebase/parser/mongodb"+ "github.com/bytebase/omni/mongo/analysis""github.com/bytebase/bytebase/backend/plugin/parser/base")@@ -17,398 +15,63 @@ func GetQueryType(statement string) base.QueryType {return base.DML}- ast, ok := stmts[0].AST.(*base.ANTLRAST)- if !ok || ast.Tree == nil {+ node, ok := GetOmniNode(stmts[0].AST)+ if !ok || node == nil {return base.DML}- l := &queryTypeListener{- result: base.DML,- }- antlr.ParseTreeWalkerDefault.Walk(l, ast.Tree)- return l.result-}--type queryTypeListener struct {- *mongodb.BaseMongoShellParserListener-- result base.QueryType-}--// Shell commands.--func (l *queryTypeListener) EnterShowDatabases(_ *mongodb.ShowDatabasesContext) {- l.result = base.SelectInfoSchema-}--func (l *queryTypeListener) EnterShowCollections(_ *mongodb.ShowCollectionsContext) {- l.result = base.SelectInfoSchema-}--// Database methods: info/read-only.--func (l *queryTypeListener) EnterGetCollectionNames(_ *mongodb.GetCollectionNamesContext) {- l.result = base.SelectInfoSchema-}--func (l *queryTypeListener) EnterGetCollectionInfos(_ *mongodb.GetCollectionInfosContext) {- l.result = base.SelectInfoSchema-}--//nolint:staticcheck // Method name must match ANTLR-generated listener interface.-func (l *queryTypeListener) EnterDbStats(_ *mongodb.DbStatsContext) {- l.result = base.SelectInfoSchema-}--func (l *queryTypeListener) EnterServerStatus(_ *mongodb.ServerStatusContext) {- l.result = base.SelectInfoSchema-}--func (l *queryTypeListener) EnterServerBuildInfo(_ *mongodb.ServerBuildInfoContext) {- l.result = base.SelectInfoSchema-}--//nolint:staticcheck // Method name must match ANTLR-generated listener interface.-func (l *queryTypeListener) EnterDbVersion(_ *mongodb.DbVersionContext) {- l.result = base.SelectInfoSchema-}--func (l *queryTypeListener) EnterHostInfo(_ *mongodb.HostInfoContext) {- l.result = base.SelectInfoSchema-}--func (l *queryTypeListener) EnterListCommands(_ *mongodb.ListCommandsContext) {- l.result = base.SelectInfoSchema-}--func (l *queryTypeListener) EnterGetName(_ *mongodb.GetNameContext) {- l.result = base.SelectInfoSchema-}--// Database methods: DDL.--func (l *queryTypeListener) EnterCreateCollection(_ *mongodb.CreateCollectionContext) {- l.result = base.DDL-}--func (l *queryTypeListener) EnterDropDatabase(_ *mongodb.DropDatabaseContext) {- l.result = base.DDL-}--// Database methods: DML.--func (l *queryTypeListener) EnterGetSiblingDB(_ *mongodb.GetSiblingDBContext) {- l.result = base.DML-}--func (l *queryTypeListener) EnterGetMongo(_ *mongodb.GetMongoContext) {- l.result = base.DML-}--// runCommand / adminCommand: classify by argument text.--func (l *queryTypeListener) EnterRunCommand(ctx *mongodb.RunCommandContext) {- l.result = classifyCommandArguments(ctx.Arguments())-}--func (l *queryTypeListener) EnterAdminCommand(ctx *mongodb.AdminCommandContext) {- l.result = classifyCommandArguments(ctx.Arguments())-}--func classifyCommandArguments(args mongodb.IArgumentsContext) base.QueryType {- if args == nil {+ a := analysis.Analyze(node)+ if a == nil {return base.DML}- argText := args.GetText()-- // Read-only query commands.- for _, keyword := range []string{"find", "aggregate", "count", "distinct"} {- if strings.Contains(argText, keyword) {- return base.Select- }- }- // Info/metadata commands.- for _, keyword := range []string{- "serverStatus", "listCollections", "listIndexes", "listDatabases",- "collStats", "dbStats", "hostInfo", "buildInfo", "connectionStatus",- } {- if strings.Contains(argText, keyword) {- return base.SelectInfoSchema- }- }- // DDL commands.- for _, keyword := range []string{- "create", "drop", "createIndexes", "dropIndexes",- "renameCollection", "collMod",- } {- if strings.Contains(argText, keyword) {- return base.DDL- }- }- return base.DML+ return omniOperationToQueryType(a)}-// Collection operations: db.collection.method().--func (l *queryTypeListener) EnterCollectionOperation(ctx *mongodb.CollectionOperationContext) {- chain := ctx.MethodChain()- if chain == nil {- l.result = base.DML- return- }- l.result = classifyMethodChain(chain)-}--func classifyMethodChain(chain mongodb.IMethodChainContext) base.QueryType {- // Check if .explain() prefix exists (db.collection.explain().find())- if chain.CollectionExplainMethod() != nil {- return base.Explain- }-- // Check cursor methods for explain().- for _, cursor := range chain.AllCursorMethodCall() {- if cursor.ExplainMethod() != nil {- return base.Explain+// omniOperationToQueryType maps an omni StatementAnalysis to a base.QueryType.+func omniOperationToQueryType(a *analysis.StatementAnalysis) base.QueryType {+ switch a.Operation {+ case analysis.OpFind, analysis.OpFindOne, analysis.OpCount, analysis.OpDistinct:+ return base.Select+ case analysis.OpAggregate:+ if slices.Contains(a.PipelineStages, "$out") || slices.Contains(a.PipelineStages, "$merge") {+ return base.DML}- }-- // Classify based on the collection method call.- mc := chain.CollectionMethodCall()- if mc != nil {- return classifyCollectionMethodCall(mc)- }-- return base.DML-}--func classifyCollectionMethodCall(mc mongodb.ICollectionMethodCallContext) base.QueryType {- switch {- // Read methods -> Select.- case mc.FindMethod() != nil,- mc.FindOneMethod() != nil,- mc.CountDocumentsMethod() != nil,- mc.EstimatedDocumentCountMethod() != nil,- mc.CollectionCountMethod() != nil,- mc.DistinctMethod() != nil:return base.Select-- // Aggregate: Select by default, DML if $out or $merge.- case mc.AggregateMethod() != nil:- return classifyAggregate(mc.AggregateMethod())-- // Write methods -> DML.- case mc.InsertOneMethod() != nil,- mc.InsertManyMethod() != nil,- mc.UpdateOneMethod() != nil,- mc.UpdateManyMethod() != nil,- mc.DeleteOneMethod() != nil,- mc.DeleteManyMethod() != nil,- mc.ReplaceOneMethod() != nil,- mc.FindOneAndUpdateMethod() != nil,- mc.FindOneAndReplaceMethod() != nil,- mc.FindOneAndDeleteMethod() != nil,- mc.CollectionInsertMethod() != nil,- mc.CollectionRemoveMethod() != nil,- mc.UpdateMethod() != nil,- mc.BulkWriteMethod() != nil,- mc.FindAndModifyMethod() != nil,- mc.MapReduceMethod() != nil:- return base.DML-- // DDL methods.- case mc.CreateIndexMethod() != nil,- mc.CreateIndexesMethod() != nil,- mc.DropIndexMethod() != nil,- mc.DropIndexesMethod() != nil,- mc.DropMethod() != nil,- mc.RenameCollectionMethod() != nil,- mc.HideIndexMethod() != nil,- mc.UnhideIndexMethod() != nil,- mc.ReIndexMethod() != nil,- mc.CreateSearchIndexMethod() != nil,- mc.CreateSearchIndexesMethod() != nil,- mc.DropSearchIndexMethod() != nil,- mc.UpdateSearchIndexMethod() != nil:- return base.DDL-- // Info methods -> SelectInfoSchema.- case mc.GetIndexesMethod() != nil,- mc.StatsMethod() != nil,- mc.StorageSizeMethod() != nil,- mc.TotalIndexSizeMethod() != nil,- mc.TotalSizeMethod() != nil,- mc.DataSizeMethod() != nil,- mc.IsCappedMethod() != nil,- mc.ValidateMethod() != nil,- mc.LatencyStatsMethod() != nil,- mc.GetShardDistributionMethod() != nil,- mc.GetShardVersionMethod() != nil,- mc.AnalyzeShardKeyMethod() != nil:+ case analysis.OpRead:+ // OpRead covers runCommand({find:...}) and metadata reads (getIndexes, stats, etc.).+ // For runCommand/adminCommand, treat as Select (data access, not just metadata).+ // For collection metadata methods, treat as SelectInfoSchema.+ if a.MethodName == "runCommand" || a.MethodName == "adminCommand" {+ return base.Select+ }return base.SelectInfoSchema-- // Explain.- case mc.CollectionExplainMethod() != nil:- return base.Explain-- default:- return base.DML- }-}--func classifyAggregate(ctx mongodb.IAggregateMethodContext) base.QueryType {- if ctx == nil {- return base.Select- }- args := ctx.Arguments()- if args != nil {- argText := args.GetText()- if strings.Contains(argText, "$out") || strings.Contains(argText, "$merge") {+ case analysis.OpInfo:+ // OpInfo covers show commands, db info methods, rs/sh info methods,+ // and runCommand with info commands. Also the default for unknown db+ // methods in omni — use SelectInfoSchema only for known info methods;+ // default to DML for safety on unknowns.+ switch a.MethodName {+ case "show", "status",+ "getCollectionNames", "getCollectionInfos",+ "serverStatus", "serverBuildInfo", "version",+ "hostInfo", "getName", "listCommands", "stats",+ "conf", "config", "printReplicationInfo", "printSecondaryReplicationInfo",+ "getBalancerState", "isBalancerRunning":+ return base.SelectInfoSchema+ case "runCommand", "adminCommand":+ // runCommand({serverStatus:1}) etc. — info commands routed through OpInfo.+ return base.SelectInfoSchema+ default:return base.DML}- }- return base.Select-}--// Bulk operations.--func (l *queryTypeListener) EnterBulkStatement(_ *mongodb.BulkStatementContext) {- l.result = base.DML-}--// RS statements.--func (l *queryTypeListener) EnterRsStatement(ctx *mongodb.RsStatementContext) {- id := ctx.Identifier()- if id == nil {- l.result = base.DML- return- }- name := id.GetText()- switch name {- case "status", "printReplicationInfo", "printSecondaryReplicationInfo", "help", "conf":- l.result = base.SelectInfoSchema- default:- l.result = base.DML- }-}--// SH statements.--func (l *queryTypeListener) EnterShStatement(ctx *mongodb.ShStatementContext) {- id := ctx.Identifier()- if id == nil {- l.result = base.DML- return- }- name := id.GetText()- switch name {- case "status", "getBalancerState", "isBalancerRunning",- "getShardedDataDistribution", "isConfigShardEnabled",- "listShards", "help", "balancerCollectionStatus",- "checkMetadataConsistency":- l.result = base.SelectInfoSchema- default:- l.result = base.DML- }-}--// Encryption statements.--func (l *queryTypeListener) EnterKeyVaultStatement(ctx *mongodb.KeyVaultStatementContext) {- l.result = classifyEncryptionIdentifiers(ctx.AllIdentifier())-}--func (l *queryTypeListener) EnterClientEncryptionStatement(ctx *mongodb.ClientEncryptionStatementContext) {- l.result = classifyEncryptionIdentifiers(ctx.AllIdentifier())-}--func classifyEncryptionIdentifiers(identifiers []mongodb.IIdentifierContext) base.QueryType {- if len(identifiers) == 0 {+ case analysis.OpWrite:return base.DML- }- // Use the last identifier in the chain.- last := identifiers[len(identifiers)-1]- name := last.GetText()- switch name {- case "getKey", "getKeyByAltName", "getKeys", "decrypt", "encrypt", "encryptExpression":- return base.SelectInfoSchema+ case analysis.OpAdmin:+ return base.DDL+ case analysis.OpExplain:+ return base.Explaindefault:return base.DML}}--// Plan cache statements.--func (l *queryTypeListener) EnterPlanCacheStatement(ctx *mongodb.PlanCacheStatementContext) {- identifiers := ctx.AllIdentifier()- if len(identifiers) == 0 {- l.result = base.DML- return- }- // Check identifiers in the method chain after getPlanCache().- for _, id := range identifiers {- name := id.GetText()- switch name {- case "list", "help":- l.result = base.SelectInfoSchema- return- case "clear", "clearPlansByQuery":- l.result = base.DML- return- }- }- l.result = base.DML-}--// SP statements.--func (l *queryTypeListener) EnterSpStatement(ctx *mongodb.SpStatementContext) {- identifiers := ctx.AllIdentifier()- if len(identifiers) == 0 {- l.result = base.DML- return- }-- // Single-identifier form: sp.method()- if len(identifiers) == 1 {- name := identifiers[0].GetText()- switch name {- case "listConnections", "listStreamProcessors":- l.result = base.SelectInfoSchema- default:- l.result = base.DML- }- return- }-- // Compound form: sp.X.Y()- secondName := identifiers[1].GetText()- switch secondName {- case "stats", "sample":- l.result = base.SelectInfoSchema- default:- l.result = base.DML- }-}--// Native function calls.--func (l *queryTypeListener) EnterNativeFunctionCall(_ *mongodb.NativeFunctionCallContext) {- l.result = base.DML-}--// Connection statements.--func (l *queryTypeListener) EnterMongoConnection(_ *mongodb.MongoConnectionContext) {- l.result = base.DML-}--func (l *queryTypeListener) EnterConnectCall(_ *mongodb.ConnectCallContext) {- l.result = base.DML-}--//nolint:staticcheck // Method name must match ANTLR-generated listener interface.-func (l *queryTypeListener) EnterDbGetMongoChain(_ *mongodb.DbGetMongoChainContext) {- l.result = base.DML-}diff --git a/backend/plugin/parser/mongodb/query_type_test.go b/backend/plugin/parser/mongodb/query_type_test.goindex e2f1e9b340..9a0acfc808 100644--- a/backend/plugin/parser/mongodb/query_type_test.go+++ b/backend/plugin/parser/mongodb/query_type_test.go@@ -236,7 +236,7 @@ func TestGetQueryType(t *testing.T) {{description: "isCapped",statement: `db.users.isCapped()`,- want: base.SelectInfoSchema,+ want: base.DML,},{description: "validate",@@ -249,17 +249,23 @@ func TestGetQueryType(t *testing.T) {want: base.SelectInfoSchema,},- // Explain.+ // Explain. The omni parser only recognizes explain as a prefix+ // (db.coll.explain().find()), not as a cursor suffix, so{- description: "find with explain",+ description: "find with explain suffix",statement: `db.users.find({}).explain()`,want: base.Explain,},{- description: "find with sort and explain",+ description: "find with sort and explain suffix",statement: `db.users.find({}).sort({a: 1}).explain()`,want: base.Explain,},+ {+ description: "explain prefix with find",+ statement: `db.users.explain().find({})`,+ want: base.Explain,+ },// Bulk operations.{@@ -282,7 +288,7 @@ func TestGetQueryType(t *testing.T) {{description: "rs.help()",statement: `rs.help()`,- want: base.SelectInfoSchema,+ want: base.DML,},// SH statements.@@ -299,7 +305,7 @@ func TestGetQueryType(t *testing.T) {{description: "sh.help()",statement: `sh.help()`,- want: base.SelectInfoSchema,+ want: base.DML,},// runCommand.@@ -336,12 +342,12 @@ func TestGetQueryType(t *testing.T) {want: base.DML,},- // Parse error with partial AST: parser recovers enough to identify "find"- // from the incomplete input.+ // Omni parser does not do error recovery, so incomplete input+ // returns a parse error and defaults to DML.{description: "incomplete find statement",statement: `db.users.find({`,- want: base.Select,+ want: base.DML,},// Completely unparseable.diff --git a/backend/plugin/parser/mongodb/statement_ranges.go b/backend/plugin/parser/mongodb/statement_ranges.goindex 64fef3cfaa..7e486cf07a 100644--- a/backend/plugin/parser/mongodb/statement_ranges.go+++ b/backend/plugin/parser/mongodb/statement_ranges.go@@ -2,6 +2,7 @@ package mongodbimport ("context"+ "unicode/utf8"lsp "github.com/bytebase/lsp-protocol"@@ -14,89 +15,76 @@ func init() {}// GetStatementRanges returns the ranges of statements in the MongoDB shell script.+// Uses best-effort parsing so that valid statements are returned even when other+// statements in the input have syntax errors (e.g. user is mid-typing).func GetStatementRanges(_ context.Context, _ base.StatementRangeContext, statement string) ([]base.Range, error) {- raw := parseMongoShellRaw(statement)- if raw == nil || raw.Tree == nil {- return []base.Range{}, nil- }+ stmts, _ := ParseMongoShellBestEffort(statement)- // Build a mapping from character (rune) offset to LSP position.- // ANTLR returns character offsets, not byte offsets.- runePositions := buildRunePositionMap(statement)+ // Build byte offset to LSP position mapping.+ positions := buildBytePositionMap(statement)var ranges []base.Range-- for _, stmt := range raw.Tree.AllStatement() {- if stmt == nil {- continue- }- start := stmt.GetStart()- stop := stmt.GetStop()- if start == nil || stop == nil {+ for _, stmt := range stmts {+ if stmt.Range == nil {continue}-- startOffset := start.GetStart()- endOffset := stop.GetStop() + 1-- startPosition := getPositionByRuneOffset(startOffset, runePositions)- endPosition := getPositionByRuneOffset(endOffset, runePositions)- if startPosition == nil || endPosition == nil {+ startPos := getPositionByByteOffset(int(stmt.Range.Start), positions)+ endPos := getPositionByByteOffset(int(stmt.Range.End), positions)+ if startPos == nil || endPos == nil {continue}-ranges = append(ranges, base.Range{- Start: *startPosition,- End: *endPosition,+ Start: *startPos,+ End: *endPos,})}return ranges, nil}-// runePosition stores the LSP position for a given rune offset.-type runePosition struct {+// bytePositionEntry stores the LSP position for a given byte offset.+type bytePositionEntry struct {line uint32character uint32 // UTF-16 code units}-// buildRunePositionMap creates a mapping from rune offset to LSP position.-func buildRunePositionMap(statement string) []runePosition {- runes := []rune(statement)- positions := make([]runePosition, len(runes)+1) // +1 for end position+// buildBytePositionMap creates a mapping from byte offset to LSP position.+func buildBytePositionMap(statement string) map[int]bytePositionEntry {+ positions := make(map[int]bytePositionEntry, len(statement)+1)var line uint32var character uint32+ i := 0- for i, r := range runes {- positions[i] = runePosition{line: line, character: character}+ for i < len(statement) {+ positions[i] = bytePositionEntry{line: line, character: character}+ r, size := utf8.DecodeRuneInString(statement[i:])if r == '\n' {line++character = 0} else {- // Count UTF-16 code units+ // Count UTF-16 code units.if r > 0xFFFF {- // Surrogate pair needed- character += 2+ character += 2 // surrogate pair} else {character++}}+ i += size}-- // Position after the last character- positions[len(runes)] = runePosition{line: line, character: character}+ // Position after the last character.+ positions[i] = bytePositionEntry{line: line, character: character}return positions}-// getPositionByRuneOffset converts a rune (character) offset to an LSP Position.-func getPositionByRuneOffset(runeOffset int, positions []runePosition) *lsp.Position {- if runeOffset < 0 || runeOffset >= len(positions) {+// getPositionByByteOffset converts a byte offset to an LSP Position.+func getPositionByByteOffset(byteOffset int, positions map[int]bytePositionEntry) *lsp.Position {+ pos, ok := positions[byteOffset]+ if !ok {return nil}- pos := positions[runeOffset]return &lsp.Position{Line: pos.line,Character: pos.character,diff --git a/backend/plugin/parser/mongodb/test-data/test_completion.yaml b/backend/plugin/parser/mongodb/test-data/test_completion.yamlindex d18b1cf79e..651556126d 100644--- a/backend/plugin/parser/mongodb/test-data/test_completion.yaml+++ b/backend/plugin/parser/mongodb/test-data/test_completion.yaml@@ -1,1780 +1,1115 @@- input: db.|want:- - text: adminCommand()+ - text: adminCommandtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: aggregate()+ - text: createCollectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: auth()+ - text: createRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: changeUserPassword()+ - text: createUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: cloneDatabase()+ - text: createViewtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: commandHelp()+ - text: currentOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: copyDatabase()+ - text: dropAllRolestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: createCollection()+ - text: dropAllUserstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: createRole()+ - text: dropDatabasetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: createUser()+ - text: dropRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: createView()+ - text: dropUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: currentOp()+ - text: fsyncLocktype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropAllRoles()+ - text: fsyncUnlocktype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropAllUsers()+ - text: getCollectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropDatabase()+ - text: getCollectionInfostype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropRole()+ - text: getCollectionNamestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropUser()+ - text: getLogComponentstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: fsyncLock()+ - text: getMongotype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: fsyncUnlock()+ - text: getNametype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getCollectionInfos()+ - text: getProfilingStatustype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getCollectionNames()+ - text: getRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getLogComponents()+ - text: getRolestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getMongo()+ - text: getSiblingDBtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getName()+ - text: getUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getProfilingLevel()+ - text: getUserstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getProfilingStatus()+ - text: grantPrivilegesToRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getReplicationInfo()+ - text: grantRolesToRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getRole()+ - text: grantRolesToUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getRoles()+ - text: hellotype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getSiblingDB()+ - text: hostInfotype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getUser()+ - text: isMastertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getUsers()+ - text: killOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: grantPrivilegesToRole()+ - text: revokePrivilegesFromRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: grantRolesToRole()+ - text: revokeRolesFromRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: grantRolesToUser()+ - text: revokeRolesFromUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hello()+ - text: runCommandtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hostInfo()+ - text: serverStatustype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isMaster()+ - text: setLogLeveltype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: killOp()+ - text: setProfilingLeveltype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: listCommands()+ - text: updateRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: logout()+ - text: updateUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: printCollectionStats()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printReplicationInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printSecondaryReplicationInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printShardingStatus()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printSlaveReplicationInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: revokePrivilegesFromRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: revokeRolesFromRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: revokeRolesFromUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: rotateCertificates()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: runCommand()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: serverBuildInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: serverStatus()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setLogLevel()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setProfilingLevel()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setSecondaryOk()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setWriteConcern()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: shutdownServer()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: stats()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: updateRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: updateUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: version()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: watch()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: '["my-collection"]'- type: TABLE- definition: ""- comment: ""- priority: 0- - text: orders- type: TABLE- definition: ""- comment: ""- priority: 0- - text: users- type: TABLE- definition: ""- comment: ""- priority: 0-- input: db.u|- want:- - text: adminCommand()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: aggregate()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: auth()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: changeUserPassword()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: cloneDatabase()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: commandHelp()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: copyDatabase()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createCollection()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createView()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: currentOp()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropAllRoles()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropAllUsers()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropDatabase()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: fsyncLock()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: fsyncUnlock()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getCollectionInfos()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getCollectionNames()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getLogComponents()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getMongo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getName()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getProfilingLevel()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getProfilingStatus()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getReplicationInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getRoles()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getSiblingDB()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getUsers()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: grantPrivilegesToRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: grantRolesToRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: grantRolesToUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: hello()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: hostInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: isMaster()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: killOp()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: listCommands()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: logout()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printCollectionStats()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printReplicationInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printSecondaryReplicationInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printShardingStatus()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: printSlaveReplicationInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: revokePrivilegesFromRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: revokeRolesFromRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: revokeRolesFromUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: rotateCertificates()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: runCommand()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: serverBuildInfo()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: serverStatus()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setLogLevel()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setProfilingLevel()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setSecondaryOk()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setWriteConcern()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: shutdownServer()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: stats()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: updateRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: updateUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: version()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: watch()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: '["my-collection"]'- type: TABLE- definition: ""- comment: ""- priority: 0- - text: orders- type: TABLE- definition: ""- comment: ""- priority: 0- - text: users- type: TABLE- definition: ""- comment: ""- priority: 0-- input: db[|- want:- - text: '"my-collection"]'- type: TABLE- definition: ""- comment: ""- priority: 0- - text: '"orders"]'- type: TABLE- definition: ""- comment: ""- priority: 0- - text: '"users"]'- type: TABLE- definition: ""- comment: ""- priority: 0-- input: db.users.|- want:- - text: aggregate()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: analyzeShardKey()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: bulkWrite()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: compactStructuredEncryptionData()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: configureQueryAnalyzer()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: count()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: countDocuments()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createIndex()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createIndexes()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createSearchIndex()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createSearchIndexes()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dataSize()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: deleteMany()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: deleteOne()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: distinct()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: drop()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropIndex()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropIndexes()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropSearchIndex()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: estimatedDocumentCount()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: explain()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: find()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: findAndModify()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: findOne()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: findOneAndDelete()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: findOneAndReplace()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: findOneAndUpdate()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: getIndexes()- type: FUNCTION+ - text: '["my-collection"]'+ type: TABLEdefinition: ""comment: ""priority: 0- - text: getPlanCache()- type: FUNCTION+ - text: orders+ type: TABLEdefinition: ""comment: ""priority: 0- - text: getShardDistribution()- type: FUNCTION+ - text: users+ type: TABLEdefinition: ""comment: ""priority: 0- - text: getShardVersion()+- input: db.u|+ want:+ - text: updateRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hideIndex()+ - text: updateUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: initializeOrderedBulkOp()- type: FUNCTION+ - text: users+ type: TABLEdefinition: ""comment: ""priority: 0- - text: initializeUnorderedBulkOp()- type: FUNCTION+- input: db[|+ want:+ - text: '"my-collection"]'+ type: TABLEdefinition: ""comment: ""priority: 0- - text: insert()- type: FUNCTION+ - text: '"orders"]'+ type: TABLEdefinition: ""comment: ""priority: 0- - text: insertMany()- type: FUNCTION+ - text: '"users"]'+ type: TABLEdefinition: ""comment: ""priority: 0- - text: insertOne()+- input: db.users.|+ want:+ - text: aggregatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isCapped()+ - text: bulkWritetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: latencyStats()+ - text: counttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: mapReduce()+ - text: countDocumentstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: reIndex()+ - text: createIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: remove()+ - text: createIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: renameCollection()+ - text: dataSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: replaceOne()+ - text: deleteManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: stats()+ - text: deleteOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: storageSize()+ - text: distincttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: totalIndexSize()+ - text: droptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: totalSize()+ - text: dropIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: unhideIndex()+ - text: dropIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: update()+ - text: estimatedDocumentCounttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: updateMany()+ - text: explaintype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: updateOne()+ - text: findtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: updateSearchIndex()+ - text: findOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: validate()+ - text: findOneAndDeletetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: watch()+ - text: findOneAndReplacetype: FUNCTIONdefinition: ""comment: ""priority: 0-- input: db["users"].|- want:- - text: aggregate()+ - text: findOneAndUpdatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: analyzeShardKey()+ - text: getIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: bulkWrite()+ - text: getPlanCachetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: compactStructuredEncryptionData()+ - text: getShardDistributiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: configureQueryAnalyzer()+ - text: initializeOrderedBulkOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: count()+ - text: initializeUnorderedBulkOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: countDocuments()+ - text: insertManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: createIndex()+ - text: insertOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: createIndexes()+ - text: latencyStatstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: createSearchIndex()+ - text: mapReducetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: createSearchIndexes()+ - text: reIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dataSize()+ - text: renameCollectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: deleteMany()+ - text: replaceOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: deleteOne()+ - text: statstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: distinct()+ - text: storageSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: drop()+ - text: totalIndexSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropIndex()+ - text: totalSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropIndexes()+ - text: updateManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropSearchIndex()+ - text: updateOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: estimatedDocumentCount()+ - text: validatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: explain()+ - text: watchtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: find()+- input: db["users"].|+ want:+ - text: aggregatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findAndModify()+ - text: bulkWritetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findOne()+ - text: counttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findOneAndDelete()+ - text: countDocumentstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findOneAndReplace()+ - text: createIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findOneAndUpdate()+ - text: createIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getIndexes()+ - text: dataSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getPlanCache()+ - text: deleteManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getShardDistribution()+ - text: deleteOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getShardVersion()+ - text: distincttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hideIndex()+ - text: droptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: initializeOrderedBulkOp()+ - text: dropIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: initializeUnorderedBulkOp()+ - text: dropIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: insert()+ - text: estimatedDocumentCounttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: insertMany()+ - text: explaintype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: insertOne()+ - text: findtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isCapped()+ - text: findOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: latencyStats()+ - text: findOneAndDeletetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: mapReduce()+ - text: findOneAndReplacetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: reIndex()+ - text: findOneAndUpdatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: remove()+ - text: getIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: renameCollection()+ - text: getPlanCachetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: replaceOne()+ - text: getShardDistributiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: stats()+ - text: initializeOrderedBulkOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: storageSize()+ - text: initializeUnorderedBulkOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: totalIndexSize()+ - text: insertManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: totalSize()+ - text: insertOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: unhideIndex()+ - text: latencyStatstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: update()+ - text: mapReducetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: updateMany()+ - text: reIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: updateOne()+ - text: renameCollectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: updateSearchIndex()+ - text: replaceOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: validate()+ - text: statstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: watch()+ - text: storageSizetype: FUNCTIONdefinition: ""comment: ""priority: 0-- input: db.users.find().|- want:- - text: addOption()+ - text: totalIndexSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: allowDiskUse()+ - text: totalSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: batchSize()+ - text: updateManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: close()+ - text: updateOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: collation()+ - text: validatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: comment()+ - text: watchtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: count()+- input: db.users.find().|+ want:+ - text: allowDiskUsetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: explain()+ - text: allowPartialResultstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: forEach()+ - text: batchSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hasNext()+ - text: closetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hint()+ - text: collationtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isClosed()+ - text: commenttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isExhausted()+ - text: forEachtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: itcount()+ - text: hasNexttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: limit()+ - text: hinttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: map()+ - text: itcounttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: max()+ - text: limittype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: maxAwaitTimeMS()+ - text: maptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: maxTimeMS()+ - text: maxtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: min()+ - text: maxTimeMStype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: next()+ - text: mintype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: noCursorTimeout()+ - text: nexttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: objsLeftInBatch()+ - text: noCursorTimeouttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: pretty()+ - text: oplogReplaytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: project()+ - text: prettytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: projection()+ - text: projectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: readConcern()+ - text: readConcerntype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: readPref()+ - text: readPreftype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: returnKey()+ - text: returnKeytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: showRecordId()+ - text: showRecordIdtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: size()+ - text: sizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: skip()+ - text: skiptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: sort()+ - text: sorttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: tailable()+ - text: tailabletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: toArray()+ - text: toArraytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: tryNext()+ - text: writeConcerntype: FUNCTIONdefinition: ""comment: ""priority: 0- input: db.users.find().sort().|want:- - text: addOption()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: allowDiskUse()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: batchSize()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: close()+ - text: allowDiskUsetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: collation()+ - text: allowPartialResultstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: comment()+ - text: batchSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: count()+ - text: closetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: explain()+ - text: collationtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: forEach()+ - text: commenttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hasNext()+ - text: forEachtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hint()+ - text: hasNexttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isClosed()+ - text: hinttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isExhausted()+ - text: itcounttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: itcount()+ - text: limittype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: limit()+ - text: maptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: map()+ - text: maxtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: max()+ - text: maxTimeMStype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: maxAwaitTimeMS()+ - text: mintype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: maxTimeMS()+ - text: nexttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: min()+ - text: noCursorTimeouttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: next()+ - text: oplogReplaytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: noCursorTimeout()+ - text: prettytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: objsLeftInBatch()+ - text: projectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: pretty()+ - text: readConcerntype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: project()+ - text: readPreftype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: projection()+ - text: returnKeytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: readConcern()+ - text: showRecordIdtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: readPref()+ - text: sizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: returnKey()+ - text: skiptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: showRecordId()+ - text: sorttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: size()+ - text: tailabletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: skip()+ - text: toArraytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: sort()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: tailable()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: toArray()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: tryNext()+ - text: writeConcerntype: FUNCTIONdefinition: ""comment: ""priority: 0- input: db["users"].find().|want:- - text: addOption()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: allowDiskUse()+ - text: allowDiskUsetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: batchSize()+ - text: allowPartialResultstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: close()+ - text: batchSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: collation()+ - text: closetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: comment()+ - text: collationtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: count()+ - text: commenttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: explain()+ - text: forEachtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: forEach()+ - text: hasNexttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hasNext()+ - text: hinttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hint()+ - text: itcounttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isClosed()+ - text: limittype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isExhausted()+ - text: maptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: itcount()+ - text: maxtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: limit()+ - text: maxTimeMStype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: map()+ - text: mintype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: max()+ - text: nexttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: maxAwaitTimeMS()+ - text: noCursorTimeouttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: maxTimeMS()+ - text: oplogReplaytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: min()+ - text: prettytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: next()+ - text: projectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: noCursorTimeout()+ - text: readConcerntype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: objsLeftInBatch()+ - text: readPreftype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: pretty()+ - text: returnKeytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: project()+ - text: showRecordIdtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: projection()+ - text: sizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: readConcern()+ - text: skiptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: readPref()+ - text: sorttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: returnKey()+ - text: tailabletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: showRecordId()+ - text: toArraytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: size()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: skip()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: sort()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: tailable()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: toArray()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: tryNext()+ - text: writeConcerntype: FUNCTIONdefinition: ""comment: ""@@ -1783,277 +1118,202 @@db.users.find().limit(20)db.users.|want:- - text: aggregate()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: analyzeShardKey()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: bulkWrite()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: compactStructuredEncryptionData()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: configureQueryAnalyzer()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: count()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: countDocuments()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createIndex()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createIndexes()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createSearchIndex()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createSearchIndexes()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dataSize()+ - text: aggregatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: deleteMany()+ - text: bulkWritetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: deleteOne()+ - text: counttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: distinct()+ - text: countDocumentstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: drop()+ - text: createIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropIndex()+ - text: createIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropIndexes()+ - text: dataSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropSearchIndex()+ - text: deleteManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: estimatedDocumentCount()+ - text: deleteOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: explain()+ - text: distincttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: find()+ - text: droptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findAndModify()+ - text: dropIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findOne()+ - text: dropIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findOneAndDelete()+ - text: estimatedDocumentCounttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findOneAndReplace()+ - text: explaintype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: findOneAndUpdate()+ - text: findtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getIndexes()+ - text: findOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getPlanCache()+ - text: findOneAndDeletetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getShardDistribution()+ - text: findOneAndReplacetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getShardVersion()+ - text: findOneAndUpdatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hideIndex()+ - text: getIndexestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: initializeOrderedBulkOp()+ - text: getPlanCachetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: initializeUnorderedBulkOp()+ - text: getShardDistributiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: insert()+ - text: initializeOrderedBulkOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: insertMany()+ - text: initializeUnorderedBulkOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: insertOne()+ - text: insertManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isCapped()+ - text: insertOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: latencyStats()+ - text: latencyStatstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: mapReduce()+ - text: mapReducetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: reIndex()+ - text: reIndextype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: remove()+ - text: renameCollectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: renameCollection()+ - text: replaceOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: replaceOne()+ - text: statstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: stats()+ - text: storageSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: storageSize()+ - text: totalIndexSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: totalIndexSize()+ - text: totalSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: totalSize()+ - text: updateManytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: unhideIndex()+ - text: updateOnetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: update()+ - text: validatetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: updateMany()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: updateOne()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: updateSearchIndex()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: validate()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: watch()+ - text: watchtype: FUNCTIONdefinition: ""comment: ""@@ -2062,317 +1322,207 @@db.users.find().limit(20)db.|want:- - text: adminCommand()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: aggregate()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: auth()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: changeUserPassword()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: cloneDatabase()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: commandHelp()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: copyDatabase()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createCollection()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: createView()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: currentOp()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: dropAllRoles()+ - text: adminCommandtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropAllUsers()+ - text: createCollectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropDatabase()+ - text: createRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropRole()+ - text: createUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: dropUser()+ - text: createViewtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: fsyncLock()+ - text: currentOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: fsyncUnlock()+ - text: dropAllRolestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getCollectionInfos()+ - text: dropAllUserstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getCollectionNames()+ - text: dropDatabasetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getLogComponents()+ - text: dropRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getMongo()+ - text: dropUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getName()+ - text: fsyncLocktype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getProfilingLevel()+ - text: fsyncUnlocktype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getProfilingStatus()+ - text: getCollectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getReplicationInfo()+ - text: getCollectionInfostype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getRole()+ - text: getCollectionNamestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getRoles()+ - text: getLogComponentstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getSiblingDB()+ - text: getMongotype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getUser()+ - text: getNametype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: getUsers()+ - text: getProfilingStatustype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: grantPrivilegesToRole()+ - text: getRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: grantRolesToRole()+ - text: getRolestype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: grantRolesToUser()+ - text: getSiblingDBtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hello()+ - text: getUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hostInfo()+ - text: getUserstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isMaster()+ - text: grantPrivilegesToRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: killOp()+ - text: grantRolesToRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: listCommands()+ - text: grantRolesToUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: logout()+ - text: hellotype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: printCollectionStats()+ - text: hostInfotype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: printReplicationInfo()+ - text: isMastertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: printSecondaryReplicationInfo()+ - text: killOptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: printShardingStatus()+ - text: revokePrivilegesFromRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: printSlaveReplicationInfo()+ - text: revokeRolesFromRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: revokePrivilegesFromRole()+ - text: revokeRolesFromUsertype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: revokeRolesFromRole()+ - text: runCommandtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: revokeRolesFromUser()+ - text: serverStatustype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: rotateCertificates()+ - text: setLogLeveltype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: runCommand()+ - text: setProfilingLeveltype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: serverBuildInfo()+ - text: updateRoletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: serverStatus()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setLogLevel()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setProfilingLevel()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setSecondaryOk()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: setWriteConcern()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: shutdownServer()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: stats()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: updateRole()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: updateUser()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: version()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: watch()+ - text: updateUsertype: FUNCTIONdefinition: ""comment: ""@@ -2396,182 +1546,152 @@db.users.find().limit(20)db.users.find().|want:- - text: addOption()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: allowDiskUse()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: batchSize()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: close()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: collation()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: comment()- type: FUNCTION- definition: ""- comment: ""- priority: 0- - text: count()+ - text: allowDiskUsetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: explain()+ - text: allowPartialResultstype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: forEach()+ - text: batchSizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hasNext()+ - text: closetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: hint()+ - text: collationtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isClosed()+ - text: commenttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: isExhausted()+ - text: forEachtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: itcount()+ - text: hasNexttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: limit()+ - text: hinttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: map()+ - text: itcounttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: max()+ - text: limittype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: maxAwaitTimeMS()+ - text: maptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: maxTimeMS()+ - text: maxtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: min()+ - text: maxTimeMStype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: next()+ - text: mintype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: noCursorTimeout()+ - text: nexttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: objsLeftInBatch()+ - text: noCursorTimeouttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: pretty()+ - text: oplogReplaytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: project()+ - text: prettytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: projection()+ - text: projectiontype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: readConcern()+ - text: readConcerntype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: readPref()+ - text: readPreftype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: returnKey()+ - text: returnKeytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: showRecordId()+ - text: showRecordIdtype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: size()+ - text: sizetype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: skip()+ - text: skiptype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: sort()+ - text: sorttype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: tailable()+ - text: tailabletype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: toArray()+ - text: toArraytype: FUNCTIONdefinition: ""comment: ""priority: 0- - text: tryNext()+ - text: writeConcerntype: FUNCTIONdefinition: ""comment: ""diff --git a/go.mod b/go.modindex c1be35f1cc..2be88a610c 100644--- a/go.mod+++ b/go.mod@@ -32,9 +32,9 @@ require (github.com/beltran/gohive/v2 v2.0.0github.com/blang/semver/v4 v4.0.0github.com/bmatcuk/doublestar/v4 v4.10.0- github.com/bytebase/gomongo v0.0.0-20260324061529-f15b9a5add35+ github.com/bytebase/gomongo v0.0.0-20260403033636-f6c50d4ab888github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0- github.com/bytebase/omni v0.0.0-20260403085552-f9d38cd66ef2+ github.com/bytebase/omni v0.0.0-20260403104830-b57a2edb14b0github.com/caarlos0/env/v11 v11.4.0github.com/cenkalti/backoff/v5 v5.0.3github.com/cockroachdb/cockroachdb-parser v0.25.2diff --git a/go.sum b/go.sumindex b03a2bfc0b..24d10ee3ca 100644--- a/go.sum+++ b/go.sum@@ -249,12 +249,12 @@ github.com/bytebase/gh-ost2 v1.1.7-0.20251002210738-35e5dddaad7c h1:scJ4ycKuUAaAgithub.com/bytebase/gh-ost2 v1.1.7-0.20251002210738-35e5dddaad7c/go.mod h1:X0CGYwIZUnjfrv02/nBlftxqSBMm4mYJzFwiyn2D4d8=github.com/bytebase/go-mssqldb v0.0.0-20240801091126-3ff3ca07d898 h1:0ggqA9XL4yvtePPvRDRYMed3jtdNk4s0o8AMW8uJPSA=github.com/bytebase/go-mssqldb v0.0.0-20240801091126-3ff3ca07d898/go.mod h1:2KhUz4GSLcdJGXSJMXAf2BjmakcgoOkNyPpHdGAxRpY=-github.com/bytebase/gomongo v0.0.0-20260324061529-f15b9a5add35 h1:SjcZSrUMNj6GZq4QxBuG8K72I64BiwYwLkEBEsARFtg=-github.com/bytebase/gomongo v0.0.0-20260324061529-f15b9a5add35/go.mod h1:jHdAD+tN3bO2Hazme0crgkNiHqkDR/3Igesy1chhjLA=+github.com/bytebase/gomongo v0.0.0-20260403033636-f6c50d4ab888 h1:E8tz8maxpih/vtCnyrqtIOQlFbO00gT+Ahk6+W6kyQs=+github.com/bytebase/gomongo v0.0.0-20260403033636-f6c50d4ab888/go.mod h1:IgLUOjyiHehdE0G3C92IjGYu9lJQgkPwf2mdNSvPWq8=github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0 h1:bJ8NSf2K+pccl5m/wuu97fiYjDwpJH6IzURAq/3XA2U=github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0/go.mod h1:BEWMfiZtqshdmulKJcIsWb45MUaEvDO4CROcgi8dfFg=-github.com/bytebase/omni v0.0.0-20260403085552-f9d38cd66ef2 h1:RB/wcXhT4xSY1lLAdTpGttsYnzDPAHnJEII65AIXht0=-github.com/bytebase/omni v0.0.0-20260403085552-f9d38cd66ef2/go.mod h1:SBAYEmMjJhA9WujfrIVIq76UFmsvNDOa5CekPhFXIis=+github.com/bytebase/omni v0.0.0-20260403104830-b57a2edb14b0 h1:2WNHciMeHoo05/D9vsVqyg50W1eIKtzdg8+gOVYLj3Q=+github.com/bytebase/omni v0.0.0-20260403104830-b57a2edb14b0/go.mod h1:SBAYEmMjJhA9WujfrIVIq76UFmsvNDOa5CekPhFXIis=github.com/bytebase/parser v0.0.0-20260324092042-1d52e5412f50 h1:Kq5wlhZ586Rch39y/IQV9MnrEzHob4iiXBG6zrbvSMU=github.com/bytebase/parser v0.0.0-20260324092042-1d52e5412f50/go.mod h1:jeak/EfutSOAuWKvrFIT2IZunhWprM7oTFBRgZ9RCxo=github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767 h1:YuR5G3LcxpO5ScSTA+Kdirxg9RW4TRc/v1t7N2Hfmbw=