“MongoDB -Graf basierend auf Array von IDs” Code-Antworten

Mongo -Grafelemente 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 }
Lucky Lobster

Mongo -Grafelemente in Array

{ $size: <expression> }
Lucky Lobster

MongoDB -Graf basierend auf Array von 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 } }
])
Witty Wildebeest

Ähnliche Antworten wie “MongoDB -Graf basierend auf Array von IDs”

Fragen ähnlich wie “MongoDB -Graf basierend auf Array von IDs”

Weitere verwandte Antworten zu “MongoDB -Graf basierend auf Array von IDs” auf TypeScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen