-
Notifications
You must be signed in to change notification settings - Fork 27
feat: support mongo connector #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
undertaker86001
wants to merge
30
commits into
infinilabs:main
Choose a base branch
from
undertaker86001:issue-456
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,732
−3
Open
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d87d5d2
mongo connector
undertaker86001 9aca2cb
add docs
undertaker86001 2f345d5
add mongodb frontend && update background
undertaker86001 645931a
add test && doc
undertaker86001 d121461
add en doc
undertaker86001 7d6dc99
remove useless doc
undertaker86001 4ce84f4
add mutli mode
undertaker86001 fb634d8
update doc
undertaker86001 f5e66b4
fix: correct syntax error in MongoDB plugin tests
devin-ai-integration[bot] cc6547f
fix connection leak
f407c4c
remove time.sleep
f793bf9
refactor: support dynamic lastsynctime
45716f8
refactor:adapter sync_strategy
f28b36f
refactor: pre-allocate slice
dec2283
add system field
undertaker86001 c0ac8aa
refactor: use task framework
undertaker86001 5e75ebe
Merge branch 'issue-456' of https://github.com/undertaker86001/coco-s…
undertaker86001 4d817e8
remove useless files
undertaker86001 fe69e19
remove useless files
undertaker86001 bb3351a
update doc
undertaker86001 df53181
remove useless doc
undertaker86001 23f0111
refactor: simpfy monitor
undertaker86001 7114911
extract common config
undertaker86001 7f1e583
Merge remote-tracking branch 'upstream/main' into issue-456
undertaker86001 dc5ae54
merge conf
undertaker86001 9aa28fb
fix test && remove useless code
ae52455
fix imports
eeeb02e
add field mapping
ebb21ef
update imports
8b7ff74
Merge remote-tracking branch 'upstream/main' into issue-456
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
undertaker86001 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// MongoDB initialization script for testing | ||
db = db.getSiblingDB('coco_test'); | ||
|
||
// Create test user | ||
db.createUser({ | ||
user: 'coco_test', | ||
pwd: 'test_password', | ||
roles: [ | ||
{ | ||
role: 'readWrite', | ||
db: 'coco_test' | ||
} | ||
] | ||
}); | ||
|
||
// Create test collections with sample data | ||
db.articles.insertMany([ | ||
{ | ||
title: "Sample Article 1", | ||
content: "This is sample content for testing", | ||
category: "Technology", | ||
tags: ["mongodb", "database"], | ||
url: "https://example.com/article1", | ||
updated_at: new Date(), | ||
status: "published" | ||
}, | ||
{ | ||
title: "Sample Article 2", | ||
content: "Another sample content for testing", | ||
category: "Programming", | ||
tags: ["go", "backend"], | ||
url: "https://example.com/article2", | ||
updated_at: new Date(), | ||
status: "draft" | ||
} | ||
]); | ||
|
||
// Create indexes for better performance | ||
db.articles.createIndex({ "updated_at": 1 }); | ||
db.articles.createIndex({ "status": 1 }); | ||
db.articles.createIndex({ "category": 1 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
version: '3.8' | ||
|
||
services: | ||
mongodb: | ||
image: mongo:7.0 | ||
container_name: coco-mongodb-test | ||
ports: | ||
- "27017:27017" | ||
environment: | ||
MONGO_INITDB_ROOT_USERNAME: admin | ||
MONGO_INITDB_ROOT_PASSWORD: password | ||
MONGO_INITDB_DATABASE: coco_test | ||
volumes: | ||
- mongodb_data:/data/db | ||
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro | ||
networks: | ||
- coco-test | ||
|
||
mongodb-replica: | ||
image: mongo:7.0 | ||
container_name: coco-mongodb-replica-test | ||
ports: | ||
- "27018:27017" | ||
command: mongod --replSet rs0 --bind_ip_all | ||
volumes: | ||
- mongodb_replica_data:/data/db | ||
networks: | ||
- coco-test | ||
|
||
volumes: | ||
mongodb_data: | ||
mongodb_replica_data: | ||
|
||
networks: | ||
coco-test: | ||
driver: bridge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# MongoDB Connector Default Configuration | ||
mongodb: | ||
# Default connection settings | ||
default_timeout: "30s" | ||
default_batch_size: 1000 | ||
default_max_pool_size: 10 | ||
|
||
# Default sync settings | ||
default_sync_strategy: "full" | ||
|
||
# Performance tuning | ||
max_concurrent_collections: 5 | ||
memory_gc_interval: 10000 | ||
|
||
# Retry settings | ||
connection_retry_attempts: 3 | ||
connection_retry_delay: "30s" | ||
|
||
# Logging | ||
log_level: "info" | ||
log_slow_queries: true | ||
slow_query_threshold: "5s" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* Copyright © INFINI LTD. All rights reserved. | ||
* Web: https://infinilabs.com | ||
* Email: hello#infini.ltd */ | ||
|
||
package mongodb | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// Config defines the configuration for the MongoDB connector | ||
type Config struct { | ||
// Connection configuration | ||
ConnectionURI string `config:"connection_uri"` | ||
Database string `config:"database"` | ||
AuthDatabase string `config:"auth_database"` // Authentication database (e.g., "admin") | ||
ClusterType string `config:"cluster_type"` // Cluster type: "standalone", "replica_set", "sharded" | ||
|
||
// Collections configuration | ||
Collections []CollectionConfig `config:"collections"` | ||
|
||
// Pagination configuration | ||
Pagination bool `config:"pagination"` | ||
PageSize int `config:"page_size"` | ||
|
||
// Last modified field for incremental sync | ||
LastModifiedField string `config:"last_modified_field"` | ||
|
||
// Performance optimization configuration | ||
BatchSize int `config:"batch_size"` | ||
Timeout string `config:"timeout"` | ||
MaxPoolSize int `config:"max_pool_size"` | ||
|
||
// Sync strategy | ||
SyncStrategy string `config:"sync_strategy"` | ||
|
||
// Field mapping configuration | ||
FieldMapping *FieldMappingConfig `config:"field_mapping"` | ||
|
||
// Advanced query optimization | ||
EnableProjection bool `config:"enable_projection"` // Enable projection pushdown | ||
EnableIndexHint bool `config:"enable_index_hint"` // Enable index hints for better performance | ||
} | ||
|
||
type CollectionConfig struct { | ||
Name string `config:"name"` | ||
Filter map[string]interface{} `config:"filter"` | ||
TitleField string `config:"title_field"` | ||
undertaker86001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ContentField string `config:"content_field"` | ||
CategoryField string `config:"category_field"` | ||
TagsField string `config:"tags_field"` | ||
URLField string `config:"url_field"` | ||
TimestampField string `config:"timestamp_field"` | ||
} | ||
|
||
// FieldMappingConfig defines the field mapping configuration | ||
type FieldMappingConfig struct { | ||
Enabled bool `config:"enabled"` | ||
Mapping map[string]interface{} `config:"mapping"` | ||
} | ||
|
||
func (p *Plugin) setDefaultConfig(config *Config) { | ||
if config.BatchSize <= 0 { | ||
config.BatchSize = 1000 | ||
} | ||
if config.MaxPoolSize <= 0 { | ||
config.MaxPoolSize = 10 | ||
} | ||
if config.Timeout == "" { | ||
config.Timeout = "30s" | ||
} | ||
if config.SyncStrategy == "" { | ||
config.SyncStrategy = "full" | ||
} | ||
if config.PageSize <= 0 { | ||
config.PageSize = 500 | ||
} | ||
if config.AuthDatabase == "" { | ||
config.AuthDatabase = "admin" // Default to admin database for authentication | ||
} | ||
if config.ClusterType == "" { | ||
config.ClusterType = "standalone" // Default to standalone MongoDB instance | ||
} | ||
if config.FieldMapping == nil { | ||
config.FieldMapping = &FieldMappingConfig{ | ||
Enabled: false, | ||
Mapping: make(map[string]interface{}), | ||
} | ||
} | ||
|
||
// Enable advanced optimizations by default for better performance | ||
if !config.EnableProjection { | ||
config.EnableProjection = true | ||
} | ||
if !config.EnableIndexHint { | ||
config.EnableIndexHint = true | ||
} | ||
} | ||
|
||
func (p *Plugin) validateConfig(config *Config) error { | ||
if config.ConnectionURI == "" { | ||
return fmt.Errorf("connection_uri must be specified") | ||
} | ||
|
||
if config.Database == "" { | ||
return fmt.Errorf("database must be specified") | ||
} | ||
|
||
if len(config.Collections) == 0 { | ||
return fmt.Errorf("at least one collection must be configured") | ||
} | ||
|
||
for i, coll := range config.Collections { | ||
if coll.Name == "" { | ||
return fmt.Errorf("collection[%d].name is required", i) | ||
} | ||
} | ||
|
||
if config.BatchSize < 0 { | ||
return fmt.Errorf("batch_size must be positive") | ||
} | ||
|
||
if config.MaxPoolSize < 0 { | ||
return fmt.Errorf("max_pool_size must be positive") | ||
} | ||
|
||
if config.PageSize < 0 { | ||
return fmt.Errorf("page_size must be positive") | ||
} | ||
|
||
if config.SyncStrategy != "" && config.SyncStrategy != "full" && config.SyncStrategy != "incremental" { | ||
return fmt.Errorf("sync_strategy must be 'full' or 'incremental'") | ||
} | ||
|
||
if config.ClusterType != "" && config.ClusterType != "standalone" && config.ClusterType != "replica_set" && config.ClusterType != "sharded" { | ||
return fmt.Errorf("cluster_type must be 'standalone', 'replica_set', or 'sharded'") | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.