Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mongodb中嵌入文档的不同值列表_Mongodb_Distinct Values_Embedded Documents_Restheart - Fatal编程技术网

mongodb中嵌入文档的不同值列表

mongodb中嵌入文档的不同值列表,mongodb,distinct-values,embedded-documents,restheart,Mongodb,Distinct Values,Embedded Documents,Restheart,我快疯了。。。我来自sql世界,这是我第一次真正体验mongodb 我有一个给定的json/对象结构(我知道,这并不完美,但由于现有数据和其他应用程序,它必须如此),存储在mongodb(v3.4)中,Restheart作为http前端 这些文件看起来像这样 { "_id" : ObjectId("5855cbc9fc3baea81e937261"), "_etag" : ObjectId("5855cbc99b971700050d8adc"), "log" : [

我快疯了。。。我来自sql世界,这是我第一次真正体验mongodb

我有一个给定的json/对象结构(我知道,这并不完美,但由于现有数据和其他应用程序,它必须如此),存储在mongodb(v3.4)中,Restheart作为http前端

这些文件看起来像这样

{
    "_id" : ObjectId("5855cbc9fc3baea81e937261"),
    "_etag" : ObjectId("5855cbc99b971700050d8adc"),
    "log" : [
        "858489b087f7472dbb8d1012dee4cd5d.d",
        NumberLong("12345678901234"),
        {
            "ext" : {
                "text" : "someone did something at somewhere (some street 123) +38 USD",
                "markup" : [
                    [
                        "user",
                        {
                            "plain" : "someone",
                            "team" : "master"
                        }
                    ], [
                        "TEXT",
                        {
                            "plain" : " did something at "
                        }
                    ], [
                        "location",
                        {
                            "name" : "somewhere",
                            "plain" : "some street 123",
                            "team" : "master"
                        }
                    ], [
                        "TEXT",
                        {
                            "plain" : "38"
                        }
                    ], [
                        "TEXT",
                        {
                            "plain" : "USD"
                        }
                    ]
                ],
                "category" : 1,
                "team" : "master"
            }
        }
    ]
}
我想得到一个清晰的用户名列表。理论上讲,
db.logs.distinct(“log.2.ext.markup.0.1.plain”)
完全可以满足我的需要。但据我所知,没有办法将db.distinct与Restheart一起使用。我尝试了使用视图,但似乎在视图中也不能使用db.distinct

这是我的实验

{ "aggrs" : [
  { "stages" : [
        { "_$project" : { "user" : "$log.2.ext.markup.0.1.plain"}},
        { "_$unwind" : "$user"},
        { "_$unwind" : "$user"},
        { "_$unwind" : "$user"},
        { "_$unwind" : "$user"},
        { "_$unwind" : "$user"},
        { "_$unwind" : "$user"},
        { "_$group" : { "_id" : "$user"}}
      ],
    "type" : "pipeline",
    "uri" : "unique_users1"
  },
  { "stages" : [
        { "_$match": { "log": { "_$exists": true, "_$ne": null }}},
        { "_$unwind" : "$log"},
        { "_$unwind" : "$log.2"},
        { "_$unwind" : "$log.2.ext"},
        { "_$unwind" : "$log.2.ext.markup"},
        { "_$unwind" : "$log.2.ext.markup.0"},
        { "_$unwind" : "$log.2.ext.markup.0.1"},
        { "_$group" : { "_id" : "$log.2.ext.markup.0.1.plain"}}
      ],
    "type" : "pipeline",
    "uri" : "unique_users2"
  },
  { "stages" : [
        { "_$match" : {"log" : { "_$exists" : true }}},
        { "_$replaceRoot" : { "newRoot" : { "user": "$log.2.ext.markup.0.1.plain"}}}
      ],
      "type" : "pipeline",
      "uri" : "unique_users3"
  },
  { "stages" : [
        { "_$group" : { "_id" : 1 , "users" : { "_$addToSet" : "$log.2.ext.markup.0.1.plain"}}}
      ],
    "type" : "pipeline",
    "uri" : "unique_users4"
  }
]}
但结果是。。。没有或几乎没有

{
"_embedded": {
    "rh:result": [
        {
            "_id": 1,
            "users": [
                []
            ]
        }
    ]
},
"_returned": 1,
"_size": 1,
"_total_pages": 1
}