我有文档集合(products_entity
(。
ID | TYPE | CONTENT_DATA
我可以通过type
查询db.getCollection('products_entity').find({type: "comment"})
来获取我的文档。
我现在想确定从查询db.getCollection('products_entity').find({type: "comment"})
返回的所有CONTENT_DATA
字段的大小。
这是可能的,我该怎么做?
或者我应该创建一个名为size
的额外列,在创建/更新时填充它并获得这些字段的总和吗?
谢谢!
您可以使用$strLenBytes或$strLenCP
db.products_entity.aggregate([
{
$addFields: {
size: {
$strLenBytes: "$CONTENT_DATA"
}
}
}
])
MongoPlayground