- Collection Extraction: New
--include-collectionCLI flag that outputs both collection name and aggregation pipeline - Enhanced API: Added
ConvertSQLToMongoWithCollection()method to the public API - Structured Output: New
ConversionResultstruct containing collection name and pipeline stages - Namespace Error Fix: Solves MongoDB
(InvalidNamespace) {aggregate: 1} is not valid for '$limit'; a collection is requirederrors
- New Flag:
--include-collection/-cflag for collection-aware output - Better Help: Updated help documentation with collection information examples
- Backward Compatibility: Existing behavior unchanged when flag is not used
// New method that returns collection name and pipeline
result, err := conv.ConvertSQLToMongoWithCollection(sqlQuery)
fmt.Printf("Collection: %s\n", result.Collection)
fmt.Printf("Pipeline: %v\n", result.Pipeline)// ConversionResult holds both collection name and pipeline
type ConversionResult struct {
Collection string `json:"collection"`
Pipeline []map[string]interface{} `json:"pipeline"`
}# Traditional output (pipeline only)
zero-sql "SELECT name FROM users LIMIT 10"
# New collection-aware output
zero-sql --include-collection "SELECT name FROM users LIMIT 10"import "github.com/synehq/zero-sql/pkg/zerosql"
conv := zerosql.New(&zerosql.Options{Verbose: false})
// Get collection and pipeline together
result, err := conv.ConvertSQLToMongoWithCollection("SELECT * FROM users LIMIT 5")
if err != nil {
return err
}
// Execute in MongoDB with proper collection
// db.collection(result.Collection).aggregate(result.Pipeline)- Issue: Generated pipelines caused
InvalidNamespaceerrors when executed in MongoDB - Root Cause: MongoDB aggregation requires explicit collection specification
- Solution: Extract collection name from SQL FROM clause and provide it alongside pipeline
- Impact: Eliminates common MongoDB execution errors when using generated pipelines
If you encounter namespace errors like:
(InvalidNamespace) {aggregate: 1} is not valid for '$limit'; a collection is requiredSolution: Use the new --include-collection flag:
zero-sql --include-collection "SELECT name FROM users LIMIT 10"This outputs:
{
"collection": "users",
"pipeline": [{"$limit": 10}]
}Then execute in MongoDB:
// MongoDB shell
db.users.aggregate([{"$limit": 10}])
// Node.js with MongoDB driver
await db.collection("users").aggregate([{"$limit": 10}]).toArray()- README: Added troubleshooting section for MongoDB namespace errors
- CLI Help: Updated examples to include new
--include-collectionflag - Usage Guide: Added collection-aware execution examples
- Zero Breaking Changes: All existing functionality remains unchanged
- Backward Compatible: Existing scripts and integrations continue to work
- Optional Feature: Collection information is opt-in via flag or method choice
- Same Performance: No performance impact on existing workflows
Full Changelog: https://github.com/synehq/zero-sql/compare/v0.0.2...v0.1.3