How to get the size of single document in Mongodb?

前端 未结 5 1566
情歌与酒
情歌与酒 2020-11-28 03:34

I encountered a strange behavior of mongo and I would like to clarify it a bit...
My request is simple as that: I would like to get a size of single document in collect

5条回答
  •  误落风尘
    2020-11-28 04:04

    With mongodb 4.4 (upcoming), You can use bsonSize operator to get the document size.

    db.test.aggregate([
      {
        "$project": {
          "name": 1,
          "object_size": { "$bsonSize": "$$ROOT" }
        }
      }
    ])
    

提交回复
热议问题