2023-01-18

MongoDB - Count the number of fields or keys in a document

 db.COLLECTION_NAME.aggregate([

    {$addFields: {

        'THIS_DOCUMENT_KEY_COUNT': {$size: {$objectToArray: "$$ROOT"}},

}},

]);

No comments:

Post a Comment