mongodb-query-builder 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mongodb_query_builder-1.0.0/CHANGELOG.md +108 -0
- mongodb_query_builder-1.0.0/LICENSE +21 -0
- mongodb_query_builder-1.0.0/MANIFEST.in +9 -0
- mongodb_query_builder-1.0.0/PKG-INFO +234 -0
- mongodb_query_builder-1.0.0/README.md +184 -0
- mongodb_query_builder-1.0.0/docs/markdown/README.md +89 -0
- mongodb_query_builder-1.0.0/docs/markdown/api/aggregate-builder.md +615 -0
- mongodb_query_builder-1.0.0/docs/markdown/api/atlas-search-builder.md +547 -0
- mongodb_query_builder-1.0.0/docs/markdown/api/query-filter.md +492 -0
- mongodb_query_builder-1.0.0/docs/markdown/getting-started.md +329 -0
- mongodb_query_builder-1.0.0/docs/markdown/migration-guide.md +690 -0
- mongodb_query_builder-1.0.0/docs/markdown/performance-guide.md +485 -0
- mongodb_query_builder-1.0.0/docs/markdown/tutorials/01-basic-queries.md +503 -0
- mongodb_query_builder-1.0.0/pyproject.toml +174 -0
- mongodb_query_builder-1.0.0/requirements.txt +2 -0
- mongodb_query_builder-1.0.0/setup.cfg +4 -0
- mongodb_query_builder-1.0.0/setup.py +13 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/__init__.py +78 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/__version__.py +19 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/builders/__init__.py +18 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/builders/aggregate_builder.py +763 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/builders/atlas_search_builder.py +856 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/builders/query_filter.py +550 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/exceptions.py +51 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/operators/__init__.py +13 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/operators/operators.py +167 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/utils/__init__.py +43 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/utils/type_helpers.py +107 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder/utils/validation.py +142 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder.egg-info/PKG-INFO +234 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder.egg-info/SOURCES.txt +36 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder.egg-info/dependency_links.txt +1 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder.egg-info/requires.txt +25 -0
- mongodb_query_builder-1.0.0/src/mongodb_query_builder.egg-info/top_level.txt +1 -0
- mongodb_query_builder-1.0.0/tests/test_aggregate_builder.py +578 -0
- mongodb_query_builder-1.0.0/tests/test_atlas_search_builder.py +643 -0
- mongodb_query_builder-1.0.0/tests/test_mongodb_integration.py +459 -0
- mongodb_query_builder-1.0.0/tests/test_query_filter.py +435 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Comprehensive documentation system with Sphinx and Markdown formats
|
|
12
|
+
- Getting Started guide with installation instructions
|
|
13
|
+
- Complete API reference documentation for all builders
|
|
14
|
+
- Tutorial: Basic Queries with exercises
|
|
15
|
+
- Migration guide for converting raw MongoDB queries
|
|
16
|
+
- Performance optimization guide
|
|
17
|
+
- Documentation build system with `make docs` commands
|
|
18
|
+
- Multiple installation methods documented (PyPI, source, GitHub)
|
|
19
|
+
|
|
20
|
+
## [1.0.0] - 2025-10-03
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
#### QueryFilter
|
|
25
|
+
- Fluent interface for building MongoDB queries
|
|
26
|
+
- Comparison operators: equals, not_equals, greater_than, less_than, between
|
|
27
|
+
- String operations: contains, starts_with, ends_with, regex
|
|
28
|
+
- Array operations: array_contains, array_contains_all, array_size, elem_match
|
|
29
|
+
- Logical operators: any_of, all_of, none_of, not_filter
|
|
30
|
+
- Existence checks: exists, is_null, is_not_null
|
|
31
|
+
- Text search support with language and sensitivity options
|
|
32
|
+
- Automatic ObjectId string conversion
|
|
33
|
+
- Comprehensive error handling with QueryFilterError
|
|
34
|
+
|
|
35
|
+
#### AggregateBuilder
|
|
36
|
+
- Fluent interface for building MongoDB aggregation pipelines
|
|
37
|
+
- Pipeline stages: match, project, group, sort, limit, skip
|
|
38
|
+
- Join operations: lookup, lookup_pipeline, graph_lookup
|
|
39
|
+
- Array operations: unwind with preserve_null and include_array_index
|
|
40
|
+
- Field manipulation: add_fields, set, unset, replace_root, replace_with
|
|
41
|
+
- Faceting: facet, bucket, bucket_auto
|
|
42
|
+
- Output stages: count, sort_by_count, sample, out, merge
|
|
43
|
+
- Union operations: union_with
|
|
44
|
+
- Advanced features: redact, custom_stage
|
|
45
|
+
- Comprehensive error handling with AggregateBuilderError
|
|
46
|
+
|
|
47
|
+
#### AtlasSearchBuilder
|
|
48
|
+
- Fluent interface for building MongoDB Atlas Search queries
|
|
49
|
+
- Search operators: text, phrase, autocomplete, wildcard, regex, range
|
|
50
|
+
- Compound queries with CompoundBuilder
|
|
51
|
+
- Clause types: must, should, must_not, filter
|
|
52
|
+
- Minimum should match configuration
|
|
53
|
+
- Faceting support with string, number, and date types
|
|
54
|
+
- Facet operator mode for advanced aggregations
|
|
55
|
+
- Score boosting and scoring functions
|
|
56
|
+
- Count configuration (lowerBound/total)
|
|
57
|
+
- More like this search
|
|
58
|
+
- Build as $search or $searchMeta stages
|
|
59
|
+
- Comprehensive error handling with AtlasSearchError
|
|
60
|
+
|
|
61
|
+
#### Testing
|
|
62
|
+
- Comprehensive test suite with 90%+ coverage
|
|
63
|
+
- Tests for QueryFilter (50+ test cases)
|
|
64
|
+
- Tests for AggregateBuilder (40+ test cases)
|
|
65
|
+
- Tests for AtlasSearchBuilder and CompoundBuilder (30+ test cases)
|
|
66
|
+
- Unit tests for all operators and methods
|
|
67
|
+
- Error handling tests
|
|
68
|
+
|
|
69
|
+
#### Documentation
|
|
70
|
+
- Comprehensive README with examples
|
|
71
|
+
- API documentation with type hints
|
|
72
|
+
- Real-world usage examples
|
|
73
|
+
- Contributing guidelines
|
|
74
|
+
- Development setup instructions
|
|
75
|
+
|
|
76
|
+
#### Project Infrastructure
|
|
77
|
+
- Modern Python packaging with pyproject.toml
|
|
78
|
+
- Setup.py for backward compatibility
|
|
79
|
+
- GitHub Actions CI/CD workflow
|
|
80
|
+
- Code quality tools: black, isort, flake8, mypy, pylint
|
|
81
|
+
- Makefile for common development tasks
|
|
82
|
+
- Requirements files for dependencies
|
|
83
|
+
- MIT License
|
|
84
|
+
- .gitignore for Python projects
|
|
85
|
+
|
|
86
|
+
### Features Highlights
|
|
87
|
+
|
|
88
|
+
- **Type Safety**: Full type hints throughout the codebase
|
|
89
|
+
- **Validation**: Built-in validation for all operations
|
|
90
|
+
- **Error Messages**: Clear, helpful error messages
|
|
91
|
+
- **Chainable API**: Fluent, chainable method calls
|
|
92
|
+
- **Python 3.8+**: Support for Python 3.8 through 3.12
|
|
93
|
+
- **Zero Breaking Changes**: Stable API from v1.0.0
|
|
94
|
+
- **Well Tested**: Comprehensive test coverage
|
|
95
|
+
- **Documentation**: Extensive documentation and examples
|
|
96
|
+
|
|
97
|
+
### Planned Features
|
|
98
|
+
- Additional aggregation operators ($densify, $fill, etc.)
|
|
99
|
+
- Enhanced Atlas Search features (geoWithin, geoShape)
|
|
100
|
+
- Async/await support with motor
|
|
101
|
+
- Performance optimizations for large pipelines
|
|
102
|
+
- Additional tutorials (Aggregation, Atlas Search, Advanced Patterns)
|
|
103
|
+
- Cookbook with real-world examples
|
|
104
|
+
- Type stub files for better IDE support
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
[1.0.0]: https://github.com/ch-dev401/mongodb-query-builder/releases/tag/v1.0.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Your Company/Name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mongodb-query-builder
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A fluent, type-safe query builder for MongoDB with support for aggregations and Atlas Search
|
|
5
|
+
Author-email: Christian De Asis <cdeasis923@gmail.comm>
|
|
6
|
+
Maintainer-email: Christian De Asis <cdeasis923@gmail.comm>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/ch-dev401/mongodb-query-builder
|
|
9
|
+
Project-URL: Documentation, https://mongodb-query-builder.readthedocs.io
|
|
10
|
+
Project-URL: Repository, https://github.com/ch-dev401/mongodb-query-builder
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/ch-dev401/mongodb-query-builder/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/ch-dev401/mongodb-query-builder/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: mongodb,query-builder,aggregation,atlas-search,database,fluent-api
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Topic :: Database
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Provides-Extra: mongodb
|
|
31
|
+
Requires-Dist: pymongo>=4.0.0; extra == "mongodb"
|
|
32
|
+
Provides-Extra: async
|
|
33
|
+
Requires-Dist: motor>=3.0.0; extra == "async"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: black>=25.9.0; extra == "dev"
|
|
36
|
+
Requires-Dist: flake8>=7.3.0; extra == "dev"
|
|
37
|
+
Requires-Dist: isort>=6.1.0; extra == "dev"
|
|
38
|
+
Requires-Dist: mypy>=1.18.2; extra == "dev"
|
|
39
|
+
Requires-Dist: pre-commit>=4.3.0; extra == "dev"
|
|
40
|
+
Requires-Dist: pylint>=3.3.8; extra == "dev"
|
|
41
|
+
Provides-Extra: test
|
|
42
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
43
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
|
|
44
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
|
|
45
|
+
Requires-Dist: mongomock>=4.1.0; extra == "test"
|
|
46
|
+
Provides-Extra: docs
|
|
47
|
+
Provides-Extra: all
|
|
48
|
+
Requires-Dist: mongodb-query-builder[async,dev,docs,mongodb,test]; extra == "all"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
# MongoDB Query Builder
|
|
52
|
+
|
|
53
|
+
A fluent, type-safe query builder for MongoDB with support for complex queries, aggregation pipelines, and Atlas Search.
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
✨ **Fluent API** - Chain methods for readable query construction
|
|
58
|
+
🔒 **Type-safe** - Full type hints and validation
|
|
59
|
+
📦 **Comprehensive** - Support for queries, aggregations, and Atlas Search
|
|
60
|
+
🎯 **Intuitive** - Pythonic interface for MongoDB operations
|
|
61
|
+
✅ **Well-tested** - Extensive test coverage
|
|
62
|
+
📚 **Well-documented** - Complete API documentation and examples
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install mongodb-query-builder
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
### Simple Query
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from mongodb_query_builder import QueryFilter
|
|
76
|
+
|
|
77
|
+
# Build a query filter
|
|
78
|
+
query = QueryFilter()\
|
|
79
|
+
.field("age").greater_than(18)\
|
|
80
|
+
.field("status").equals("active")\
|
|
81
|
+
.build()
|
|
82
|
+
|
|
83
|
+
# Use with pymongo
|
|
84
|
+
collection.find(query)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Aggregation Pipeline
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from mongodb_query_builder import AggregateBuilder, QueryFilter
|
|
91
|
+
|
|
92
|
+
# Build aggregation pipeline
|
|
93
|
+
pipeline = AggregateBuilder()\
|
|
94
|
+
.match(QueryFilter().field("status").equals("active"))\
|
|
95
|
+
.group(by="$category", count={"$sum": 1}, total={"$sum": "$amount"})\
|
|
96
|
+
.sort("count", ascending=False)\
|
|
97
|
+
.limit(10)\
|
|
98
|
+
.build()
|
|
99
|
+
|
|
100
|
+
# Use with pymongo
|
|
101
|
+
results = collection.aggregate(pipeline)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Atlas Search
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from mongodb_query_builder import AtlasSearchBuilder, CompoundBuilder
|
|
108
|
+
|
|
109
|
+
# Simple text search
|
|
110
|
+
search = AtlasSearchBuilder()\
|
|
111
|
+
.text("python developer", path=["title", "description"])\
|
|
112
|
+
.build_stage()
|
|
113
|
+
|
|
114
|
+
# Complex compound search
|
|
115
|
+
compound = CompoundBuilder()
|
|
116
|
+
compound.must().text("python", path="skills")
|
|
117
|
+
compound.should().text("senior", path="level", score=2.0)
|
|
118
|
+
compound.filter().range("experience", gte=3)
|
|
119
|
+
|
|
120
|
+
search = AtlasSearchBuilder()\
|
|
121
|
+
.compound(compound)\
|
|
122
|
+
.facet("departments", type="string", path="department")\
|
|
123
|
+
.build_stage()
|
|
124
|
+
|
|
125
|
+
# Use in aggregation
|
|
126
|
+
pipeline = [search, {"$limit": 10}]
|
|
127
|
+
results = collection.aggregate(pipeline)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Core Components
|
|
131
|
+
|
|
132
|
+
### QueryFilter
|
|
133
|
+
|
|
134
|
+
Build MongoDB query filters with a fluent interface:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from mongodb_query_builder import QueryFilter
|
|
138
|
+
|
|
139
|
+
# Comparison operators
|
|
140
|
+
q = QueryFilter().field("age").greater_than(18)
|
|
141
|
+
q = QueryFilter().field("price").between(10, 100)
|
|
142
|
+
|
|
143
|
+
# String operations
|
|
144
|
+
q = QueryFilter().field("name").starts_with("John")
|
|
145
|
+
q = QueryFilter().field("email").contains("@example.com")
|
|
146
|
+
|
|
147
|
+
# Array operations
|
|
148
|
+
q = QueryFilter().field("tags").array_contains("python")
|
|
149
|
+
q = QueryFilter().field("skills").array_contains_all(["python", "mongodb"])
|
|
150
|
+
|
|
151
|
+
# Logical operators
|
|
152
|
+
q = QueryFilter().any_of([
|
|
153
|
+
QueryFilter().field("role").equals("admin"),
|
|
154
|
+
QueryFilter().field("role").equals("moderator")
|
|
155
|
+
])
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### AggregateBuilder
|
|
159
|
+
|
|
160
|
+
Build aggregation pipelines:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from mongodb_query_builder import AggregateBuilder
|
|
164
|
+
|
|
165
|
+
pipeline = AggregateBuilder()\
|
|
166
|
+
.match(QueryFilter().field("status").equals("active"))\
|
|
167
|
+
.group(by="$category", count={"$sum": 1})\
|
|
168
|
+
.sort("count", ascending=False)\
|
|
169
|
+
.limit(10)\
|
|
170
|
+
.project(category="$_id", count=1, _id=0)\
|
|
171
|
+
.build()
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### AtlasSearchBuilder
|
|
175
|
+
|
|
176
|
+
Build Atlas Search queries:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from mongodb_query_builder import AtlasSearchBuilder, CompoundBuilder
|
|
180
|
+
|
|
181
|
+
# Text search with fuzzy matching
|
|
182
|
+
search = AtlasSearchBuilder()\
|
|
183
|
+
.text("search term", path="title", fuzzy={"maxEdits": 2})\
|
|
184
|
+
.build_stage()
|
|
185
|
+
|
|
186
|
+
# Compound search
|
|
187
|
+
compound = CompoundBuilder()
|
|
188
|
+
compound.must().text("required term", path="content")
|
|
189
|
+
compound.should().text("optional term", path="tags", score=2.0)
|
|
190
|
+
compound.filter().range("date", gte=datetime(2024, 1, 1))
|
|
191
|
+
|
|
192
|
+
search = AtlasSearchBuilder().compound(compound).build_stage()
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Requirements
|
|
196
|
+
|
|
197
|
+
- Python 3.8+
|
|
198
|
+
- pymongo (optional, for MongoDB operations)
|
|
199
|
+
- typing-extensions (for Python < 3.10)
|
|
200
|
+
|
|
201
|
+
## Documentation
|
|
202
|
+
|
|
203
|
+
### 📚 Getting Started
|
|
204
|
+
- [Installation & Quick Start](docs/markdown/getting-started.md)
|
|
205
|
+
- [Basic Queries Tutorial](docs/markdown/tutorials/01-basic-queries.md)
|
|
206
|
+
|
|
207
|
+
### 🔧 API Reference
|
|
208
|
+
- [QueryFilter API](docs/markdown/api/query-filter.md) - Query building methods
|
|
209
|
+
- [AggregateBuilder API](docs/markdown/api/aggregate-builder.md) - Aggregation pipeline methods
|
|
210
|
+
- [AtlasSearchBuilder API](docs/markdown/api/atlas-search-builder.md) - Atlas Search methods
|
|
211
|
+
|
|
212
|
+
### 📖 Guides
|
|
213
|
+
- [Migration Guide](docs/markdown/migration-guide.md) - Convert from raw MongoDB queries
|
|
214
|
+
- [Performance Guide](docs/markdown/performance-guide.md) - Optimization best practices
|
|
215
|
+
|
|
216
|
+
### 🛠️ Development
|
|
217
|
+
- [Contributing Guidelines](CONTRIBUTING.md)
|
|
218
|
+
|
|
219
|
+
### 📐 Full Documentation
|
|
220
|
+
- [Documentation Overview](docs/markdown/README.md) - Complete documentation index
|
|
221
|
+
- Online documentation available at: *(coming soon)*
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
226
|
+
|
|
227
|
+
## Contributing
|
|
228
|
+
|
|
229
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](docs/CONTRIBUTING.md) for guidelines.
|
|
230
|
+
|
|
231
|
+
## Support
|
|
232
|
+
|
|
233
|
+
- GitHub Issues: [Report bugs or request features](https://github.com/ch-dev401/mongodb-query-builder/issues)
|
|
234
|
+
- Documentation: [Full documentation](https://github.com/ch-dev401/mongodb-query-builder)
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# MongoDB Query Builder
|
|
2
|
+
|
|
3
|
+
A fluent, type-safe query builder for MongoDB with support for complex queries, aggregation pipelines, and Atlas Search.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
✨ **Fluent API** - Chain methods for readable query construction
|
|
8
|
+
🔒 **Type-safe** - Full type hints and validation
|
|
9
|
+
📦 **Comprehensive** - Support for queries, aggregations, and Atlas Search
|
|
10
|
+
🎯 **Intuitive** - Pythonic interface for MongoDB operations
|
|
11
|
+
✅ **Well-tested** - Extensive test coverage
|
|
12
|
+
📚 **Well-documented** - Complete API documentation and examples
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install mongodb-query-builder
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Simple Query
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from mongodb_query_builder import QueryFilter
|
|
26
|
+
|
|
27
|
+
# Build a query filter
|
|
28
|
+
query = QueryFilter()\
|
|
29
|
+
.field("age").greater_than(18)\
|
|
30
|
+
.field("status").equals("active")\
|
|
31
|
+
.build()
|
|
32
|
+
|
|
33
|
+
# Use with pymongo
|
|
34
|
+
collection.find(query)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Aggregation Pipeline
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from mongodb_query_builder import AggregateBuilder, QueryFilter
|
|
41
|
+
|
|
42
|
+
# Build aggregation pipeline
|
|
43
|
+
pipeline = AggregateBuilder()\
|
|
44
|
+
.match(QueryFilter().field("status").equals("active"))\
|
|
45
|
+
.group(by="$category", count={"$sum": 1}, total={"$sum": "$amount"})\
|
|
46
|
+
.sort("count", ascending=False)\
|
|
47
|
+
.limit(10)\
|
|
48
|
+
.build()
|
|
49
|
+
|
|
50
|
+
# Use with pymongo
|
|
51
|
+
results = collection.aggregate(pipeline)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Atlas Search
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from mongodb_query_builder import AtlasSearchBuilder, CompoundBuilder
|
|
58
|
+
|
|
59
|
+
# Simple text search
|
|
60
|
+
search = AtlasSearchBuilder()\
|
|
61
|
+
.text("python developer", path=["title", "description"])\
|
|
62
|
+
.build_stage()
|
|
63
|
+
|
|
64
|
+
# Complex compound search
|
|
65
|
+
compound = CompoundBuilder()
|
|
66
|
+
compound.must().text("python", path="skills")
|
|
67
|
+
compound.should().text("senior", path="level", score=2.0)
|
|
68
|
+
compound.filter().range("experience", gte=3)
|
|
69
|
+
|
|
70
|
+
search = AtlasSearchBuilder()\
|
|
71
|
+
.compound(compound)\
|
|
72
|
+
.facet("departments", type="string", path="department")\
|
|
73
|
+
.build_stage()
|
|
74
|
+
|
|
75
|
+
# Use in aggregation
|
|
76
|
+
pipeline = [search, {"$limit": 10}]
|
|
77
|
+
results = collection.aggregate(pipeline)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Core Components
|
|
81
|
+
|
|
82
|
+
### QueryFilter
|
|
83
|
+
|
|
84
|
+
Build MongoDB query filters with a fluent interface:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from mongodb_query_builder import QueryFilter
|
|
88
|
+
|
|
89
|
+
# Comparison operators
|
|
90
|
+
q = QueryFilter().field("age").greater_than(18)
|
|
91
|
+
q = QueryFilter().field("price").between(10, 100)
|
|
92
|
+
|
|
93
|
+
# String operations
|
|
94
|
+
q = QueryFilter().field("name").starts_with("John")
|
|
95
|
+
q = QueryFilter().field("email").contains("@example.com")
|
|
96
|
+
|
|
97
|
+
# Array operations
|
|
98
|
+
q = QueryFilter().field("tags").array_contains("python")
|
|
99
|
+
q = QueryFilter().field("skills").array_contains_all(["python", "mongodb"])
|
|
100
|
+
|
|
101
|
+
# Logical operators
|
|
102
|
+
q = QueryFilter().any_of([
|
|
103
|
+
QueryFilter().field("role").equals("admin"),
|
|
104
|
+
QueryFilter().field("role").equals("moderator")
|
|
105
|
+
])
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### AggregateBuilder
|
|
109
|
+
|
|
110
|
+
Build aggregation pipelines:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from mongodb_query_builder import AggregateBuilder
|
|
114
|
+
|
|
115
|
+
pipeline = AggregateBuilder()\
|
|
116
|
+
.match(QueryFilter().field("status").equals("active"))\
|
|
117
|
+
.group(by="$category", count={"$sum": 1})\
|
|
118
|
+
.sort("count", ascending=False)\
|
|
119
|
+
.limit(10)\
|
|
120
|
+
.project(category="$_id", count=1, _id=0)\
|
|
121
|
+
.build()
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### AtlasSearchBuilder
|
|
125
|
+
|
|
126
|
+
Build Atlas Search queries:
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from mongodb_query_builder import AtlasSearchBuilder, CompoundBuilder
|
|
130
|
+
|
|
131
|
+
# Text search with fuzzy matching
|
|
132
|
+
search = AtlasSearchBuilder()\
|
|
133
|
+
.text("search term", path="title", fuzzy={"maxEdits": 2})\
|
|
134
|
+
.build_stage()
|
|
135
|
+
|
|
136
|
+
# Compound search
|
|
137
|
+
compound = CompoundBuilder()
|
|
138
|
+
compound.must().text("required term", path="content")
|
|
139
|
+
compound.should().text("optional term", path="tags", score=2.0)
|
|
140
|
+
compound.filter().range("date", gte=datetime(2024, 1, 1))
|
|
141
|
+
|
|
142
|
+
search = AtlasSearchBuilder().compound(compound).build_stage()
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Requirements
|
|
146
|
+
|
|
147
|
+
- Python 3.8+
|
|
148
|
+
- pymongo (optional, for MongoDB operations)
|
|
149
|
+
- typing-extensions (for Python < 3.10)
|
|
150
|
+
|
|
151
|
+
## Documentation
|
|
152
|
+
|
|
153
|
+
### 📚 Getting Started
|
|
154
|
+
- [Installation & Quick Start](docs/markdown/getting-started.md)
|
|
155
|
+
- [Basic Queries Tutorial](docs/markdown/tutorials/01-basic-queries.md)
|
|
156
|
+
|
|
157
|
+
### 🔧 API Reference
|
|
158
|
+
- [QueryFilter API](docs/markdown/api/query-filter.md) - Query building methods
|
|
159
|
+
- [AggregateBuilder API](docs/markdown/api/aggregate-builder.md) - Aggregation pipeline methods
|
|
160
|
+
- [AtlasSearchBuilder API](docs/markdown/api/atlas-search-builder.md) - Atlas Search methods
|
|
161
|
+
|
|
162
|
+
### 📖 Guides
|
|
163
|
+
- [Migration Guide](docs/markdown/migration-guide.md) - Convert from raw MongoDB queries
|
|
164
|
+
- [Performance Guide](docs/markdown/performance-guide.md) - Optimization best practices
|
|
165
|
+
|
|
166
|
+
### 🛠️ Development
|
|
167
|
+
- [Contributing Guidelines](CONTRIBUTING.md)
|
|
168
|
+
|
|
169
|
+
### 📐 Full Documentation
|
|
170
|
+
- [Documentation Overview](docs/markdown/README.md) - Complete documentation index
|
|
171
|
+
- Online documentation available at: *(coming soon)*
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
176
|
+
|
|
177
|
+
## Contributing
|
|
178
|
+
|
|
179
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](docs/CONTRIBUTING.md) for guidelines.
|
|
180
|
+
|
|
181
|
+
## Support
|
|
182
|
+
|
|
183
|
+
- GitHub Issues: [Report bugs or request features](https://github.com/ch-dev401/mongodb-query-builder/issues)
|
|
184
|
+
- Documentation: [Full documentation](https://github.com/ch-dev401/mongodb-query-builder)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# MongoDB Query Builder Documentation
|
|
2
|
+
|
|
3
|
+
Welcome to the MongoDB Query Builder documentation! This library provides a fluent, type-safe interface for constructing MongoDB queries, aggregation pipelines, and Atlas Search operations.
|
|
4
|
+
|
|
5
|
+
## 📚 Documentation Overview
|
|
6
|
+
|
|
7
|
+
### Getting Started
|
|
8
|
+
- [Installation & Quick Start](getting-started.md) - How to install and get started with MongoDB Query Builder
|
|
9
|
+
- Basic Concepts - Understanding QueryFilter, AggregateBuilder, and AtlasSearchBuilder
|
|
10
|
+
|
|
11
|
+
### Tutorials
|
|
12
|
+
Step-by-step guides for learning the library:
|
|
13
|
+
|
|
14
|
+
1. [Basic Queries](tutorials/01-basic-queries.md) - Simple queries and filters ✅
|
|
15
|
+
2. Aggregation Pipelines *(coming soon)* - Building complex data pipelines
|
|
16
|
+
3. Atlas Search *(coming soon)* - Full-text search with Atlas
|
|
17
|
+
4. Advanced Patterns *(coming soon)* - Complex query patterns and optimization
|
|
18
|
+
|
|
19
|
+
### API Reference
|
|
20
|
+
Detailed documentation for all components:
|
|
21
|
+
|
|
22
|
+
- [QueryFilter](api/query-filter.md) - Building MongoDB query filters ✅
|
|
23
|
+
- [AggregateBuilder](api/aggregate-builder.md) - Constructing aggregation pipelines ✅
|
|
24
|
+
- [AtlasSearchBuilder](api/atlas-search-builder.md) - Atlas Search queries ✅
|
|
25
|
+
|
|
26
|
+
### Guides
|
|
27
|
+
- [Migration Guide](migration-guide.md) - Converting raw MongoDB queries ✅
|
|
28
|
+
- [Performance Guide](performance-guide.md) - Query optimization tips ✅
|
|
29
|
+
|
|
30
|
+
### Cookbook *(coming soon)*
|
|
31
|
+
Real-world examples and patterns:
|
|
32
|
+
|
|
33
|
+
- User Authentication - User login and permission queries
|
|
34
|
+
- Product Catalog - E-commerce search and filtering
|
|
35
|
+
- Analytics Pipeline - Data aggregation for analytics
|
|
36
|
+
- Time Series - Working with time-series data
|
|
37
|
+
|
|
38
|
+
## 🚀 Quick Example
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from mongodb_query_builder import QueryFilter, AggregateBuilder
|
|
42
|
+
|
|
43
|
+
# Simple query
|
|
44
|
+
query = QueryFilter()
|
|
45
|
+
.field("age").greater_than(18)
|
|
46
|
+
.field("status").equals("active")
|
|
47
|
+
.build()
|
|
48
|
+
|
|
49
|
+
# Aggregation pipeline
|
|
50
|
+
pipeline = AggregateBuilder()
|
|
51
|
+
.match(QueryFilter().field("status").equals("active"))
|
|
52
|
+
.group(by="$category", count={"$sum": 1})
|
|
53
|
+
.sort("count", ascending=False)
|
|
54
|
+
.limit(10)
|
|
55
|
+
.build()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 🔍 Finding What You Need
|
|
59
|
+
|
|
60
|
+
- **New to MongoDB Query Builder?** Start with the [Getting Started Guide](getting-started.md)
|
|
61
|
+
- **Looking for specific functionality?** Check the [API Reference](#api-reference)
|
|
62
|
+
- **Need examples?** Browse the [Cookbook](#cookbook) *(coming soon)*
|
|
63
|
+
- **Having issues?** Check our [GitHub Issues](https://github.com/ch-dev401/mongodb-query-builder/issues)
|
|
64
|
+
|
|
65
|
+
## 📖 Documentation Versions
|
|
66
|
+
|
|
67
|
+
This documentation is available in two formats:
|
|
68
|
+
|
|
69
|
+
1. **Markdown Documentation** (this version) - GitHub-friendly, easy to browse
|
|
70
|
+
2. **Sphinx Documentation** - Full API documentation with search functionality
|
|
71
|
+
|
|
72
|
+
## 🤝 Contributing
|
|
73
|
+
|
|
74
|
+
We welcome contributions! See our [Contributing Guide](../../CONTRIBUTING.md) for details on:
|
|
75
|
+
- Reporting issues
|
|
76
|
+
- Suggesting features
|
|
77
|
+
- Submitting pull requests
|
|
78
|
+
- Documentation improvements
|
|
79
|
+
|
|
80
|
+
## 📄 License
|
|
81
|
+
|
|
82
|
+
MongoDB Query Builder is released under the MIT License. See the [LICENSE](../../LICENSE) file for details.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
**Need help?**
|
|
87
|
+
- 📧 Open an issue on [GitHub](https://github.com/ch-dev401/mongodb-query-builder/issues)
|
|
88
|
+
- 💬 Join our [community discussions](https://github.com/ch-dev401/mongodb-query-builder/discussions)
|
|
89
|
+
- 📚 Read the [documentation](getting-started.md)
|