MongoDB查询Gmail数据

时间:2016-11-20 21:26:03

标签: mongodb gmail nosql

我启用了Google Gmail API,但我遇到了MongoDB查询问题(第一次这样做)。我想得到邮件正文大小超过100的电子邮件的数量。

我有这个:

db.gmail_data.aggregate(
    [
        { $match: { 'payloads.parts.body.size': { $gt: 100 } }},
        { $group: { _id: null, count: { $sum: 1 }}}
    ]
);

我最终收到此消息:Failed to call method", "code" : 1。对不起如果简单的错误,我对NoSQL完全不熟悉。文档中的数据如下所示:

{
    _id:"AAA",
    snippet:"",
    historyId:"AAA",
    labelIds:[
        "IMPORTANT",
        "SENT",
        "INBOX"
    ],
    threadId:"AAA",
    sizeEstimate:24281,
    id:"AAA",
    internalDate:"123123213",
    payload:{
        mimeType:"multipart/mixed",
        filename:"",
        headers:[
            {
                name:"Return-Path",
                value:"<email@gmail.com>"
            },
            {
                name:"Received",
                value:"from [ip_here] (metadata)"
            },
            {
                name:"To",
                value:"email@gmail.com"
            },
            {
                name:"From",
                value:"Byron <email@gmail.com>"
            },
            {
                name:"Subject",
                value:"Some subject"
            },
            {
                name:"Message-ID",
                value:"<message_id@gmail.com>"
            },
            {
                name:"Date",
                value:"Fri, 12 Nov 2011 05:17:54 -0200"
            },
            {
                name:"User-Agent",
                value:"Some user-agen"
            },
            {
                name:"MIME-Version",
                value:"1.0"
            },
            {
                name:"Content-Type",
                value:"Some content-type"
            }
        ],
        parts:[
            {
                mimeType:"text/plain",
                filename:"",
                headers:[
                    {
                        name:"Content-Type",
                        value:"text/plain; charset=utf-8; format=flowed"
                    },
                    {
                        name:"Content-Transfer-Encoding",
                        value:"7bit"
                    }
                ],
                partId:"0",
                body:{
                    data:"453",
                    size:2
                }
            },
            {
                mimeType:"text/plain",
                filename:"file.zip",
                headers:[
                    {
                        name:"Content-Type",
                        value:"text/plain; charset=UTF-8; name="file.zip""
                    },
                    {
                        name:"Content-Transfer-Encoding",
                        value:"base64"
                    },
                    {
                        name:"Content-Disposition",
                        value:"attachment; filename="file.zip""
                    }
                ],
                partId:"1",
                body:{
                    size:14219,
                    attachmentId:"AAB"
                }
            },
            {
                mimeType:"text/plain",
                filename:"file2.zip",
                headers:[
                    {
                        name:"Content-Type",
                        value:"text/plain; charset=UTF-8; name="file2.zip""
                    },
                    {
                        name:"Content-Transfer-Encoding",
                        value:"base64"
                    },
                    {
                        name:"Content-Disposition",
                        value:"attachment; filename="file2.zip""
                    }
                ],
                partId:"2",
                body:{
                    size:2503,
                    attachmentId:"AAC"
                }
            }
        ],
        body:{
            size:0
        }
    }
}

如何获取JSON中每个位置的信息?我试着查看MongoDB网站上的文档并提出上面的查询,但我无法弄清楚是什么问题。

任何帮助将不胜感激。谢谢!

0 个答案:

没有答案