mongo

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: Apache-2.0 Imports: 15 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 {
	Client           *mongo.Client
	Database         *mongo.Database
	DriverCredential *models.DriverCredentials
}

func GetMongoDriver

func GetMongoDriver(driverCredentials *models.DriverCredentials) (*MongoDriver, error)

func (*MongoDriver) AddCollection

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

AddCollection adds a new collection to the project

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, repeatedGroupIdentifier 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) CheckCollectionExists

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

CheckCollectionExists checks if a collection exists in the project

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) 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, repeatedGroupIdentifier string) error

func (*MongoDriver) CreateRelation

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

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 implements the deletion of a project

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

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

NewInsertableRelations retrieves new insertable relations in the project.

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