Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

mongo count elements in array

> db.mycollection.insert({'foo':[1,2,3,4]})
> db.mycollection.insert({'foo':[5,6,7]})

> db.mycollection.aggregate([{$project: { count: { $size:"$foo" }}}])
{ "_id" : ObjectId("5314b5c360477752b449eedf"), "count" : 4 }
{ "_id" : ObjectId("5314b5c860477752b449eee0"), "count" : 3 }
Comment

mongo count elements in array

{ $size: <expression> }
Comment

Mongodb count based on array of ids

db.collection.aggregate([
    { $unwind: "$connects" },

    // count all occurrences
    { "$group": { "_id": {skill: "$skill", parser_id: "$connects.parser_id"}, "count": { "$sum": 1 } }},

    // sum all occurrences and count distinct
    { "$group": { "_id": "$_id.skill", "quantity": { "$sum": 1 } }},

    // (optional) rename the '_id' attribute to 'skill'
    { $project: { 'skill': '$_id', 'quantity': 1, _id: 0 } }
])
Comment

PREVIOUS NEXT
Code Example
Typescript :: To list all tcp ports. 
Typescript :: how to get value from autocomplete material ui 
Typescript :: push at first index typescript 
Typescript :: initialize empty array typescript 
Typescript :: typescript endless loop 
Typescript :: wordpress get_posts custom posts by meta key 
Typescript :: how to check is null or empty in typescript 
Typescript :: typescript import particular class from file 
Typescript :: print elements of unordered set c++ 
Typescript :: typeorm query builder update relations filed 
Typescript :: js split at index 
Typescript :: 2 decimal points react native 
Typescript :: React.ComponentProps<T 
Typescript :: get elements in list in another list c# 
Typescript :: python requests use proxy 
Typescript :: moment datepicker 
Typescript :: generic in typescript 
Typescript :: Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. 
Typescript :: angular currency pipe pt-br as variable 
Typescript :: ANGULAR: create component in module 
Typescript :: git delete commits from remote 
Typescript :: how push objects into a local stotage array 
Typescript :: select constraints in sql 
Typescript :: typescript import css 
Typescript :: git squash commits on branch 
Typescript :: how to install downloaded requirements pip with python 
Typescript :: avatar image mui not centered 
Typescript :: shortid typescript 
Typescript :: latest unity version that supports 32 bit 
Typescript :: angular start date end date validation 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =