mongo

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

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

This section is empty.

Types

type MongoDriver

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

func GetProjectMongoDriver added in v1.6.0

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 adds a document to a project

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)

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 added in v1.6.0

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 in a project

func (*MongoDriver) CreateIndex

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

func (*MongoDriver) CreateRelation

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

func (*MongoDriver) CreateTableOrCollection added in v1.6.0

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}_media 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 a document from a project

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

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) DeleteProjectBase added in v1.6.0

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) 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

func (*MongoDriver) DropIndex

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

func (*MongoDriver) DropModel

func (m *MongoDriver) DropModel(ctx context.Context, project *models.Project, modelName string) 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) 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 gets a single document from a project

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 added in v1.6.0

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) NewInsertableRelations

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

NewInsertableRelations retrieves new insertable relations in the project.

func (*MongoDriver) Ping added in v1.1.4

func (m *MongoDriver) Ping() error

func (*MongoDriver) QueryMultiDocumentOfProject

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

QueryMultiDocumentOfProject retrieves multiple documents from a project

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

func (*MongoDriver) RenameModel

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

func (*MongoDriver) SearchFunctions

func (*MongoDriver) SearchWebHooks

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 in a project

Jump to

Keyboard shortcuts

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