Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common_helper_mongo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
common_helper_mongo
Commits
41435cf9
Commit
41435cf9
authored
May 02, 2019
by
Jörg Stucke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
further refactoring
parent
9248e735
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
aggregate.py
common_helper_mongo/aggregate.py
+6
-5
No files found.
common_helper_mongo/aggregate.py
View file @
41435cf9
...
...
@@ -2,6 +2,7 @@ import logging
from
typing
import
List
,
Optional
from
bson.son
import
SON
from
pymongo.command_cursor
import
CommandCursor
def
get_list_of_all_values
(
collection
,
object_path
,
unwind
=
False
,
match
=
None
):
...
...
@@ -142,11 +143,11 @@ def get_field_average(collection, object_path, match=None):
def
get_field_execute_operation
(
operation
,
collection
,
object_path
,
match
=
None
):
pipeline
=
_build_pipeline
(
object_path
,
{
'_id'
:
'null'
,
'total'
:
{
operation
:
object_path
}},
match
=
match
)
query
=
collection
.
aggregate
(
pipeline
)
result
=
0
for
item
in
query
:
result
=
item
[
'total'
]
return
result
query
_result
=
collection
.
aggregate
(
pipeline
)
try
:
return
query_result
.
next
()[
'total'
]
except
StopIteration
:
return
0
def
_build_pipeline
(
object_path
:
str
,
group
:
dict
,
unwind
:
bool
=
False
,
sort_key
:
Optional
[
SON
]
=
None
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment