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 ¶
- type Factory
- type Service
- func (s *Service) AddColumn(ctx context.Context, table string, column driver.ColumnDef) error
- func (s *Service) AlterColumn(ctx context.Context, table string, change driver.ColumnChange) error
- func (s *Service) BrowseTable(ctx context.Context, name string, browse driver.BrowseOptions) (driver.Result, error)
- func (s *Service) Close() error
- func (s *Service) CreateForeignKey(ctx context.Context, table string, change driver.ForeignKeyChange) error
- func (s *Service) CreateIndex(ctx context.Context, table string, change driver.IndexChange) error
- func (s *Service) DeleteDocument(ctx context.Context, collection string, id driver.DocumentPayload) (driver.Result, error)
- func (s *Service) DropColumn(ctx context.Context, table, name string) error
- func (s *Service) DropForeignKey(ctx context.Context, table, previous string) error
- func (s *Service) DropIndex(ctx context.Context, table, name string) error
- func (s *Service) Execute(ctx context.Context, input string) (driver.Result, error)
- func (s *Service) ExecuteReadOnly(ctx context.Context, input string) (driver.Result, error)
- func (s *Service) Info() driver.DatabaseInfo
- func (s *Service) InsertDocument(ctx context.Context, collection string, doc driver.DocumentPayload) (driver.Result, error)
- func (s *Service) ListForeignKeys(ctx context.Context, table string) ([]driver.ForeignKeyInfo, error)
- func (s *Service) ListForeignKeysAll(ctx context.Context) (map[string][]driver.ForeignKeyInfo, error)
- func (s *Service) ListIndexes(ctx context.Context, table string) ([]driver.IndexInfo, error)
- func (s *Service) ListIndexesAll(ctx context.Context) (map[string][]driver.IndexInfo, error)
- func (s *Service) ListReferencingForeignKeys(ctx context.Context, table string) ([]driver.ReferencingForeignKeyInfo, error)
- func (s *Service) ListSchema(ctx context.Context) ([]driver.SchemaObject, error)
- func (s *Service) ReadDocument(ctx context.Context, collection string, id driver.DocumentPayload) (driver.DocumentPayload, error)
- func (s *Service) ReplaceDocument(ctx context.Context, collection string, id driver.DocumentPayload, ...) (driver.Result, error)
- func (s *Service) ReplaceForeignKey(ctx context.Context, table, previous string, change driver.ForeignKeyChange) error
- func (s *Service) ReplaceIndex(ctx context.Context, table, previous string, change driver.IndexChange) error
- func (s *Service) TableInfo(ctx context.Context, name string) ([]driver.ColumnInfo, error)
- func (s *Service) Validate(ctx context.Context, statement string) error
- func (s *Service) WorkspaceView(ctx context.Context, request driver.WorkspaceViewRequest) (driver.Result, error)
- func (s *Service) WriteCapabilities() driver.WriteCapabilities
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) BuildTarget(_ context.Context, values driver.FormValues) (driver.BuildTargetResult, error)
func (Factory) Capabilities ¶ added in v0.11.0
func (Factory) Capabilities() driver.Capabilities
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 ¶
Open connects to the MongoDB URI and selects the database from its path (default "test", matching the mongo shell).
func (*Service) AlterColumn ¶
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) CreateForeignKey ¶
func (*Service) CreateIndex ¶
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 (*Service) DropForeignKey ¶
func (*Service) ExecuteReadOnly ¶
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 (*Service) ListForeignKeysAll ¶
func (*Service) ListIndexes ¶
ListIndexes reports the real MongoDB indexes of a collection.
func (*Service) ListIndexesAll ¶
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 (*Service) ListSchema ¶
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 (*Service) ReplaceIndex ¶
func (*Service) TableInfo ¶
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 ¶
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 (*Service) WriteCapabilities ¶
func (s *Service) WriteCapabilities() driver.WriteCapabilities
WriteCapabilities reports MongoDB's document-write capability: relaxed extended JSON, editable as whole-document text.