mongo

package
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 21 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

MongoDB Driver for Apito Engine

This package implements the interfaces.ProjectDBInterface for MongoDB database support in Apito Engine.

Implementation Status

The MongoDB driver currently implements the following core functionality:

  • Basic document operations (create, read, update, delete)
  • Collection management
  • Project management
  • Document querying and counting

Many advanced features like relationships, field manipulations, and certain specialized queries are currently marked as "not implemented" and will return appropriate errors. These features will be implemented in future iterations as needed.

Configuration

To use the MongoDB driver, make sure to include the MongoDB credentials in your configuration:

driverCredentials := &models.DriverCredentials{
    Engine:   _const.MongoDBDriver,
    Host:     "127.0.0.1",  // MongoDB server host
    Port:     "27017",      // MongoDB server port
    User:     "username",   // MongoDB username
    Password: "password",   // MongoDB password
    Database: "apito_project", // Database name
}

Usage

The MongoDB driver is automatically selected in the GetProjectDriver function when the driver engine is set to _const.MongoDBDriver:

import (
    "github.com/apito-io/buffers/protobuff"
    "github.com/apito-io/engine/database/project"
    _const "github.com/apito-io/engine/const"
)

func main() {
    driverCredentials := &models.DriverCredentials{
        Engine:   _const.MongoDBDriver,
        Host:     "127.0.0.1",
        Port:     "27017",
        User:     "username",
        Password: "password",
        Database: "apito_project",
    }

    driver, err := project.GetProjectDriver(driverCredentials)
    if err != nil {
        // Handle error
    }

    // Use the driver
    // ...
}

Dependencies

This driver requires the MongoDB Go Driver:

go get go.mongodb.org/mongo-driver/mongo

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApitoBSONRegistry added in v1.0.35

func ApitoBSONRegistry() *bson.Registry

ApitoBSONRegistry is the registry with the types.ID codecs, for other MongoDB clients (system driver) that store the same types.

func CheckConnection added in v1.0.35

func CheckConnection(ctx context.Context, cred *models.DriverCredentials) (string, error)

CheckConnection connects with the same URI rules as GetProjectMongoDriver, pings, reads the server version and disconnects. It creates nothing.

Types

type MongoDriver

type MongoDriver struct {
	Conf             *models.Config
	Client           *mongo.Client
	Database         *mongo.Database
	DriverCredential *models.DriverCredentials
}

func GetProjectMongoDriver

func GetProjectMongoDriver(conf *models.Config, driverCredentials *models.DriverCredentials) (*MongoDriver, error)

func (*MongoDriver) AddDocumentToProject

func (m *MongoDriver) AddDocumentToProject(ctx context.Context, param *models.CommonSystemParams, doc *types.DefaultDocumentStructure) (interface{}, error)

AddDocumentToProject stores a document. Ids on MongoDB are ObjectID hex strings (types.ID — used for tenant_id references — only accepts those), so a caller id is kept only when it already is one; otherwise a new id is assigned. Callers read the stored id back from the returned document.

func (*MongoDriver) AddFieldToModel

func (m *MongoDriver) AddFieldToModel(ctx context.Context, param *models.CommonSystemParams, isUpdate bool, parent_field string) (*models.ModelType, error)

AddFieldToModel adds a new field to an existing model in the project.

func (*MongoDriver) AddModel

func (m *MongoDriver) AddModel(ctx context.Context, project *models.Project, model *models.ModelType) (*models.ProjectSchema, error)

func (*MongoDriver) AddRelationFields

func (m *MongoDriver) AddRelationFields(ctx context.Context, from *models.ConnectionType, to *models.ConnectionType) error

func (*MongoDriver) AddTeamMetaInfo

func (m *MongoDriver) AddTeamMetaInfo(ctx context.Context, users []*models.SystemUser) ([]*models.SystemUser, error)

func (*MongoDriver) AggregateDocOfProject

func (m *MongoDriver) AggregateDocOfProject(ctx context.Context, param *models.CommonSystemParams) (interface{}, error)

AggregateDocOfProject sums the selected numeric fields (or counts) over the list filter.

func (*MongoDriver) AggregateDocOfProjectBytes

func (m *MongoDriver) AggregateDocOfProjectBytes(ctx context.Context, param *models.CommonSystemParams) ([]byte, error)

func (*MongoDriver) CheckOneToOneRelationExists

func (m *MongoDriver) CheckOneToOneRelationExists(ctx context.Context, param *models.ConnectDisconnectParam) (bool, error)

CheckOneToOneRelationExists checks if a one-to-one relation exists in the project.

func (*MongoDriver) CheckTableOrCollectionExists

func (m *MongoDriver) CheckTableOrCollectionExists(ctx context.Context, param *models.CommonSystemParams) (bool, error)

CheckTableOrCollectionExists checks if a collection exists in the project. When param.Ext[models.ExtKeyRelationCollectionCheck] is true, checks relation_{model} instead of the model collection.

func (*MongoDriver) ConnectBuilder

func (m *MongoDriver) ConnectBuilder(ctx context.Context, param *models.CommonSystemParams) error

ConnectBuilder connects a builder to the project.

func (*MongoDriver) ConvertModel

func (m *MongoDriver) ConvertModel(ctx context.Context, project *models.Project, modelName string) error

func (*MongoDriver) CountDocOfProject

func (m *MongoDriver) CountDocOfProject(ctx context.Context, param *models.CommonSystemParams) (interface{}, error)

func (*MongoDriver) CountDocOfProjectBytes

func (m *MongoDriver) CountDocOfProjectBytes(ctx context.Context, param *models.CommonSystemParams) ([]byte, error)

func (*MongoDriver) CountMultiDocumentOfProject

func (m *MongoDriver) CountMultiDocumentOfProject(ctx context.Context, param *models.CommonSystemParams, previewModel bool) (int, error)

CountMultiDocumentOfProject counts documents matching the list filter.

func (*MongoDriver) CountProjectAuthUsersByRole

func (m *MongoDriver) CountProjectAuthUsersByRole(ctx context.Context, tenantID string) (map[string]int, error)

func (*MongoDriver) CreateIndex

func (m *MongoDriver) CreateIndex(ctx context.Context, param *models.CommonSystemParams, fieldName string, parent_field string) error

CreateIndex indexes a field of a model.

func (*MongoDriver) CreateProjectAuthUser

func (m *MongoDriver) CreateProjectAuthUser(ctx context.Context, user *models.ProjectAuthUser) (*models.ProjectAuthUser, error)

func (*MongoDriver) CreateProjectFile

func (m *MongoDriver) CreateProjectFile(ctx context.Context, file *models.ProjectFile) (*models.ProjectFile, error)

func (*MongoDriver) CreateRelation

func (m *MongoDriver) CreateRelation(ctx context.Context, projectId string, relation *models.EdgeRelation) error

func (*MongoDriver) CreateTableOrCollection

func (m *MongoDriver) CreateTableOrCollection(ctx context.Context, param *models.CommonSystemParams, indexes []string) error

CreateTableOrCollection creates a new table or collection in the project. For general project bootstrap, param.Model may be nil: in that case (and when not creating a relation collection) the primary bucket p_{projectID} and p_{projectID}_files are created, matching Arango AddCollection which does not require a model for the default collection name.

func (*MongoDriver) DeleteDocumentFromProject

func (m *MongoDriver) DeleteDocumentFromProject(ctx context.Context, param *models.CommonSystemParams) error

DeleteDocumentFromProject deletes one document (and its edges are left to DeleteDocumentRelation).

func (*MongoDriver) DeleteDocumentRelation

func (m *MongoDriver) DeleteDocumentRelation(ctx context.Context, param *models.CommonSystemParams) error

DeleteDocumentRelation deletes all relations or data in pivot tables from the project.

func (*MongoDriver) DeleteDocumentsFromProject

func (m *MongoDriver) DeleteDocumentsFromProject(ctx context.Context, param *models.CommonSystemParams) error

DeleteDocumentsFromProject deletes several documents by id.

func (*MongoDriver) DeleteProject

func (m *MongoDriver) DeleteProject(ctx context.Context, projectId string) error

DeleteProject removes the project’s physical collections; it delegates to DeleteProjectBase (same scope as InitProjectBase).

func (*MongoDriver) DeleteProjectAuthUser

func (m *MongoDriver) DeleteProjectAuthUser(ctx context.Context, userID string) error

func (*MongoDriver) DeleteProjectBase

func (m *MongoDriver) DeleteProjectBase(ctx context.Context, param *models.CommonSystemParams) error

DeleteProjectBase drops the collections created by InitProjectBase for this project (p_{id}, media, relation).

func (*MongoDriver) DeleteProjectFiles

func (m *MongoDriver) DeleteProjectFiles(ctx context.Context, ids []string) error

func (*MongoDriver) DeleteRelation

func (m *MongoDriver) DeleteRelation(ctx context.Context, param *models.ConnectDisconnectParam, id string) error

func (*MongoDriver) DeleteRelationDocuments

func (m *MongoDriver) DeleteRelationDocuments(ctx context.Context, projectId string, from *models.ConnectionType, to *models.ConnectionType) error

func (*MongoDriver) DisconnectBuilder

func (m *MongoDriver) DisconnectBuilder(ctx context.Context, param *models.CommonSystemParams) error

DisconnectBuilder disconnects a builder from the project.

func (*MongoDriver) DropField

func (m *MongoDriver) DropField(ctx context.Context, param *models.CommonSystemParams) error

DropField removes a field from every document of the model.

func (*MongoDriver) DropIndex

func (m *MongoDriver) DropIndex(ctx context.Context, param *models.CommonSystemParams, indexName string) error

DropIndex removes an index by name (missing indexes are ignored).

func (*MongoDriver) DropModel

func (m *MongoDriver) DropModel(ctx context.Context, project *models.Project, modelName string) error

DropModel deletes a model's documents and edge collections.

func (*MongoDriver) EnsureFilesTable

func (m *MongoDriver) EnsureFilesTable(ctx context.Context) error

func (*MongoDriver) EnsureRelationArtifactsFromSchema

func (m *MongoDriver) EnsureRelationArtifactsFromSchema(ctx context.Context, modelsList []*models.ModelType) error

EnsureRelationArtifactsFromSchema is a no-op. Mongo relation storage is the edge collection created by AddRelationFields; there is no separate column or pivot pass.

func (*MongoDriver) EnsureUsersTable

func (m *MongoDriver) EnsureUsersTable(ctx context.Context) error

func (*MongoDriver) GetAllRelationDocumentsOfSingleDocument

func (m *MongoDriver) GetAllRelationDocumentsOfSingleDocument(ctx context.Context, from string, arg *models.CommonSystemParams) (interface{}, error)

GetAllRelationDocumentsOfSingleDocument retrieves all relation data of a single document by ID.

func (*MongoDriver) GetLoggedInProjectUser

func (m *MongoDriver) GetLoggedInProjectUser(ctx context.Context, param *models.CommonSystemParams) (*types.DefaultDocumentStructure, error)

GetLoggedInProjectUser retrieves the logged-in user profile for the project

func (*MongoDriver) GetProject

func (m *MongoDriver) GetProject(ctx context.Context, id string) (*models.Project, error)

GetProject retrieves a project by ID

func (*MongoDriver) GetProjectAuthUser

func (m *MongoDriver) GetProjectAuthUser(ctx context.Context, userID string) (*models.ProjectAuthUser, error)

func (*MongoDriver) GetProjectAuthUserByUsername

func (m *MongoDriver) GetProjectAuthUserByUsername(ctx context.Context, username string) (*models.ProjectAuthUser, error)

func (*MongoDriver) GetProjectFile

func (m *MongoDriver) GetProjectFile(ctx context.Context, fileID string) (*models.ProjectFile, error)

func (*MongoDriver) GetProjectUser

func (m *MongoDriver) GetProjectUser(ctx context.Context, phone, email, projectId string) (*types.DefaultDocumentStructure, error)

GetProjectUser retrieves a user profile by phone, email, and project ID

func (*MongoDriver) GetProjectUsers

func (m *MongoDriver) GetProjectUsers(ctx context.Context, projectId string, keys []string) (map[string]*types.DefaultDocumentStructure, error)

GetProjectUsers retrieves metadata for multiple users in the project

func (*MongoDriver) GetRelationDocument

func (m *MongoDriver) GetRelationDocument(ctx context.Context, param *models.ConnectDisconnectParam) (*models.EdgeRelation, error)

func (*MongoDriver) GetRelationIds

func (m *MongoDriver) GetRelationIds(ctx context.Context, param *models.ConnectDisconnectParam) ([]string, error)

GetRelationIds retrieves the IDs of every document related to a document.

func (*MongoDriver) GetSingleProjectDocument

func (m *MongoDriver) GetSingleProjectDocument(ctx context.Context, param *models.CommonSystemParams) (*types.DefaultDocumentStructure, error)

GetSingleProjectDocument reads one document by id.

func (*MongoDriver) GetSingleProjectDocumentBytes

func (m *MongoDriver) GetSingleProjectDocumentBytes(ctx context.Context, param *models.CommonSystemParams) ([]byte, error)

GetSingleProjectDocumentBytes retrieves a single project document by ID as bytes.

func (*MongoDriver) GetSingleProjectDocumentRevisions

func (m *MongoDriver) GetSingleProjectDocumentRevisions(ctx context.Context, param *models.CommonSystemParams) ([]*models.DocumentRevisionHistory, error)

GetSingleProjectDocumentRevisions retrieves the revision history of a single project document by ID.

func (*MongoDriver) GetSingleRawDocumentFromProject

func (m *MongoDriver) GetSingleRawDocumentFromProject(ctx context.Context, param *models.CommonSystemParams) (interface{}, error)

func (*MongoDriver) GetWebHook

func (m *MongoDriver) GetWebHook(ctx context.Context, projectId, hookId string) (*models.Webhook, error)

func (*MongoDriver) InitProjectBase

func (m *MongoDriver) InitProjectBase(ctx context.Context, param *models.CommonSystemParams, indexes []string) error

InitProjectBase creates the default media bucket, relation collection (with edge indexes), and main document collection p_{projectID} with standard document indexes. Driver v2 CreateCollection returns only error; use Database.Collection after CreateCollection.

func (*MongoDriver) ListProjectAuthUsersByEmail

func (m *MongoDriver) ListProjectAuthUsersByEmail(ctx context.Context, tenantID, email string) ([]*models.ProjectAuthUser, error)

func (*MongoDriver) ListProjectAuthUsersByGoogleSub

func (m *MongoDriver) ListProjectAuthUsersByGoogleSub(ctx context.Context, tenantID, googleSub string) ([]*models.ProjectAuthUser, error)

func (*MongoDriver) ListProjectAuthUsersByOAuthSub

func (m *MongoDriver) ListProjectAuthUsersByOAuthSub(ctx context.Context, tenantID, provider, oauthSub string) ([]*models.ProjectAuthUser, error)

func (*MongoDriver) ListProjectAuthUsersByPhone

func (m *MongoDriver) ListProjectAuthUsersByPhone(ctx context.Context, tenantID, phone string) ([]*models.ProjectAuthUser, error)

func (*MongoDriver) MigrateRelationCardinality

func (m *MongoDriver) MigrateRelationCardinality(ctx context.Context, req *relationmigrate.Request) (*relationmigrate.Receipt, error)

func (*MongoDriver) NewInsertableRelations

func (m *MongoDriver) NewInsertableRelations(ctx context.Context, param *models.ConnectDisconnectParam) ([]string, error)

NewInsertableRelations retrieves new insertable relations in the project.

func (*MongoDriver) Ping

func (m *MongoDriver) Ping() error

func (*MongoDriver) PreviewRelationCardinalityMigration

func (m *MongoDriver) PreviewRelationCardinalityMigration(ctx context.Context, req *relationmigrate.Request) (*relationmigrate.Preview, error)

func (*MongoDriver) QueryMultiDocumentOfProject

func (m *MongoDriver) QueryMultiDocumentOfProject(ctx context.Context, param *models.CommonSystemParams) ([]*types.DefaultDocumentStructure, error)

QueryMultiDocumentOfProject lists documents of a model with filters, sort and paging.

func (*MongoDriver) QueryMultiDocumentOfProjectBytes

func (m *MongoDriver) QueryMultiDocumentOfProjectBytes(ctx context.Context, param *models.CommonSystemParams) ([]byte, error)

func (*MongoDriver) RelationshipDataLoader

func (m *MongoDriver) RelationshipDataLoader(ctx context.Context, param *models.CommonSystemParams, connection map[string]interface{}) (interface{}, error)

RelationshipDataLoader loads relationship data for the project.

func (*MongoDriver) RelationshipDataLoaderBytes

func (m *MongoDriver) RelationshipDataLoaderBytes(ctx context.Context, param *models.CommonSystemParams, connection map[string]interface{}) ([]byte, error)

RelationshipDataLoaderBytes loads relationship data for the project and returns it as bytes.

func (*MongoDriver) RenameField

func (m *MongoDriver) RenameField(ctx context.Context, oldFieldName string, repeatedFieldGroup string, param *models.CommonSystemParams) error

RenameField renames a field on every document of the model.

func (*MongoDriver) RenameModel

func (m *MongoDriver) RenameModel(ctx context.Context, project *models.Project, modelName, newName string) error

RenameModel renames a model: its documents' type, its edge collections and the edges' model names.

func (*MongoDriver) SearchFunctions

func (*MongoDriver) SearchProjectAuthUsers

func (m *MongoDriver) SearchProjectAuthUsers(ctx context.Context, tenantID, q string, limit, offset int) ([]*models.ProjectAuthUser, int, error)

func (*MongoDriver) SearchProjectFiles

func (*MongoDriver) SearchWebHooks

func (*MongoDriver) SumProjectFilesSize

func (m *MongoDriver) SumProjectFilesSize(ctx context.Context) (int64, error)

func (*MongoDriver) TransferProject

func (m *MongoDriver) TransferProject(ctx context.Context, userId, from, to string) error

TransferProject transfers a project from one user to another

func (*MongoDriver) UpdateDocumentOfProject

func (m *MongoDriver) UpdateDocumentOfProject(ctx context.Context, param *models.CommonSystemParams, doc *types.DefaultDocumentStructure, replace bool) error

UpdateDocumentOfProject updates a document. Without replace only the given fields change (like the SQL drivers); with replace the document is rewritten.

func (*MongoDriver) UpdateProjectAuthUser

func (m *MongoDriver) UpdateProjectAuthUser(ctx context.Context, user *models.ProjectAuthUser) error

func (*MongoDriver) VerifyRelationCardinalityMigration

func (m *MongoDriver) VerifyRelationCardinalityMigration(ctx context.Context, req *relationmigrate.Request) (*relationmigrate.Receipt, error)

Jump to

Keyboard shortcuts

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