如何在mongo中获取嵌入式数组的大小? [英] how to get embedded array's size in mongo?

查看:72
本文介绍了如何在mongo中获取嵌入式数组的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在MongoDB中查询内部数组大小

Possible Duplicate:
Querying internal array size in MongoDB

我有一个包含数组category的文档.我只想知道category中有多少个项目.我在文档中只能找到如何计算顶级文档的数量.

I have a document which contains an array category. I just want to know how many items there are in category. All I could find in the documentation is how to count the number of top level documents.

{
 "_id": {
     "$oid": "4e73a30466ca1a1f56000001"
    },
 "category": [
     "Food",
     "Entertainment"
    ]
}

推荐答案

添加新字段以处理类别大小.这是mongo世界中的常规做法.

Add new field to hande category size. It's a usual practice in mongo world.

这篇关于如何在mongo中获取嵌入式数组的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆