Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

mongodb group by having

#It's the equivalent of the following SQL instruction:
# SELECT COUNT(*) FROM Table
# GROUP BY your_field
# HAVING COUNT(*) > N
query = db.collection.aggregate([

    { 
      "$group": { "_id": "$your_field", #GROUP BY your_field
    			"count": {"$sum":1} }   #COUNT(*)
    },
    
    { "$match": { "count": { "$gt": N } } } #HAVING COUNT(*) > N
])
Comment

mongodb aggregate group

#equivalent of the following SQL instruction:
# SELECT COUNT(*) FROM Table
# GROUP BY your_field
query = db.collection.aggregate([
    { 
        "$group": {
            "_id": "$your_field", #GROUP BY your_field
            "total": {"$sum":1}   #COUNT(*)
        }
    }
])
Comment

PREVIOUS NEXT
Code Example
Python :: measure time 
Python :: python print green 
Python :: pytorch transpose 
Python :: how to bulk update in mongodb using python 
Python :: midpoint 
Python :: numpy aray map values with dictionary 
Python :: numpy int64 to int 
Python :: how to run python program in sublime text 3 windows 
Python :: fibonacci series list comphrehension in python 
Python :: uninstall python using powershell 
Python :: charat in python 
Python :: scipy cosine similarity 
Python :: pygame get keypress code 
Python :: virtualenv python2 
Python :: python recursively merge dictionaries 
Python :: python string startswith regex 
Python :: reading json file 
Python :: audioplayer python 
Python :: how to sort a list descending python 
Python :: soap 1.2 request python 
Python :: reverse element in a list in python 3 
Python :: Write a Python program to sum all the items in a dictionary. 
Python :: python dictionary delete by value 
Python :: get requests python 
Python :: python for/else 
Python :: word embedding python 
Python :: how to take date as input in python 
Python :: create a superuser to access django admin 
Python :: pie plot in python 
Python :: python sockets 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =