mongodb

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package mongodb implements the shared database service contract against MongoDB. Connections open one database (the URI path, default "test"); the schema pane lists that database's collections, which map to tables.

The query editor accepts mongosh-style statements instead of SQL:

db.<collection>.find([filter[, projection]])[.sort(doc)][.skip(n)][.limit(n)][.project(doc)]
db.<collection>.findOne([filter[, projection]])
db.<collection>.countDocuments([filter])
db.<collection>.estimatedDocumentCount()
db.<collection>.aggregate([pipeline])
db.<collection>.distinct(field[, filter])
db.<collection>.insertOne(doc)
db.<collection>.insertMany([docs])
db.<collection>.updateOne(filter, update[, {upsert: true}])
db.<collection>.updateMany(filter, update[, {upsert: true}])
db.<collection>.replaceOne(filter, doc[, {upsert: true}])
db.<collection>.deleteOne([filter])
db.<collection>.deleteMany([filter])
db.<collection>.drop()
db.<collection>.createIndex(keys[, options])
show collections
show dbs

Arguments are JSON documents in MongoDB extended-JSON relaxed form, so dates and ObjectIds can be written as {"$date": ...} / {"$oid": "..."}; ObjectId("...") is also accepted as a shorthand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory added in v0.11.0

type Factory struct{}

func (Factory) BuildTarget added in v0.11.0

func (Factory) Capabilities added in v0.11.0

func (Factory) Capabilities() driver.Capabilities

func (Factory) Open added in v0.11.0

func (Factory) Open(ctx context.Context, target string) (driver.OpenResult, error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a MongoDB driver implementing the shared database contract. Collections map to tables; the structure tab shows sampled fields.

func Open

func Open(ctx context.Context, target string) (*Service, error)

Open connects to the MongoDB URI and selects the database from its path (default "test", matching the mongo shell).

func (*Service) AddColumn

func (s *Service) AddColumn(ctx context.Context, table string, column driver.ColumnDef) error

func (*Service) AlterColumn

func (s *Service) AlterColumn(ctx context.Context, table string, change driver.ColumnChange) error

func (*Service) BrowseTable

func (s *Service) BrowseTable(ctx context.Context, name string, browse driver.BrowseOptions) (driver.Result, error)

BrowseTable queries a collection with the shared filter/sort/paging options. The Columns projection is ignored: documents carry their own fields, so restricting to sampled columns would hide data.

func (*Service) Close

func (s *Service) Close() error

func (*Service) CreateForeignKey

func (s *Service) CreateForeignKey(ctx context.Context, table string, change driver.ForeignKeyChange) error

func (*Service) CreateIndex

func (s *Service) CreateIndex(ctx context.Context, table string, change driver.IndexChange) error

func (*Service) DeleteDocument

func (s *Service) DeleteDocument(ctx context.Context, collection string, id driver.DocumentPayload) (driver.Result, error)

DeleteDocument removes the document identified by id.

func (*Service) DropColumn

func (s *Service) DropColumn(ctx context.Context, table, name string) error

func (*Service) DropForeignKey

func (s *Service) DropForeignKey(ctx context.Context, table, previous string) error

func (*Service) DropIndex

func (s *Service) DropIndex(ctx context.Context, table, name string) error

func (*Service) Execute

func (s *Service) Execute(ctx context.Context, input string) (driver.Result, error)

func (*Service) ExecuteReadOnly

func (s *Service) ExecuteReadOnly(ctx context.Context, input string) (driver.Result, error)

func (*Service) Info

func (s *Service) Info() driver.DatabaseInfo

func (*Service) InsertDocument

func (s *Service) InsertDocument(ctx context.Context, collection string, doc driver.DocumentPayload) (driver.Result, error)

InsertDocument inserts one document from its extended-JSON payload. Non-document bodies (arrays, scalars, malformed text) fail without mutating data.

func (*Service) ListForeignKeys

func (s *Service) ListForeignKeys(ctx context.Context, table string) ([]driver.ForeignKeyInfo, error)

func (*Service) ListForeignKeysAll

func (s *Service) ListForeignKeysAll(ctx context.Context) (map[string][]driver.ForeignKeyInfo, error)

func (*Service) ListIndexes

func (s *Service) ListIndexes(ctx context.Context, table string) ([]driver.IndexInfo, error)

ListIndexes reports the real MongoDB indexes of a collection.

func (*Service) ListIndexesAll

func (s *Service) ListIndexesAll(ctx context.Context) (map[string][]driver.IndexInfo, error)

ListIndexesAll returns every collection's indexes, keyed by collection name. The driver API has no bulk index listing, so each collection is queried once.

func (*Service) ListReferencingForeignKeys

func (s *Service) ListReferencingForeignKeys(ctx context.Context, table string) ([]driver.ReferencingForeignKeyInfo, error)

func (*Service) ListSchema

func (s *Service) ListSchema(ctx context.Context) ([]driver.SchemaObject, error)

ListSchema reports the connected database root and its collections. Other databases are not advertised: table operations carry only a collection name and would silently target the connected database.

func (*Service) ReadDocument

func (s *Service) ReadDocument(ctx context.Context, collection string, id driver.DocumentPayload) (driver.DocumentPayload, error)

ReadDocument loads the complete document identified by id. The id payload is the extended-JSON encoding of the _id value (a scalar), not a full document.

func (*Service) ReplaceDocument

func (s *Service) ReplaceDocument(ctx context.Context, collection string, id driver.DocumentPayload, doc driver.DocumentPayload) (driver.Result, error)

ReplaceDocument is whole-document replacement: the replacement must be a document whose _id is absent or BSON-equal to the requested identity; the requested _id is injected when absent. RowsAffected reports MatchedCount.

func (*Service) ReplaceForeignKey

func (s *Service) ReplaceForeignKey(ctx context.Context, table, previous string, change driver.ForeignKeyChange) error

func (*Service) ReplaceIndex

func (s *Service) ReplaceIndex(ctx context.Context, table, previous string, change driver.IndexChange) error

func (*Service) TableInfo

func (s *Service) TableInfo(ctx context.Context, name string) ([]driver.ColumnInfo, error)

TableInfo reports the fields observed in a document sample. _id is the implicit primary key; every other field is nullable and untyped beyond the BSON type seen in the sample.

func (*Service) Validate

func (s *Service) Validate(ctx context.Context, statement string) error

Validate parses the statement without executing it, so syntax and JSON errors surface while typing without any side effects.

func (*Service) WorkspaceView added in v0.11.0

func (s *Service) WorkspaceView(ctx context.Context, request driver.WorkspaceViewRequest) (driver.Result, error)

func (*Service) WriteCapabilities

func (s *Service) WriteCapabilities() driver.WriteCapabilities

WriteCapabilities reports MongoDB's document-write capability: relaxed extended JSON, editable as whole-document text.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL