如何使用pymongo在多个元素上创建单个索引?

时间:2019-04-15 15:03:36

标签: database mongodb python-2.7 indexing pymongo

我有一个包含以下文档的集合: `

{
    "_id" : ObjectId("5cae17d0bb8f3e2d3fd56c04"),
    "created" : ISODate("2019-04-10T18:20:32.310Z"),
    "date1" : ISODate("2019-05-09T09:30:00.000Z"),
    "type" : "referes",
    "state" : "running",
    "date2" : ISODate("2019-01-09T00:00:00.000Z"),
    "firstList" : [ 
       {
        "hair" : "blond",
        "name" : "paul",
        "address" : {
                     "city" : "Paris",
                     "streetAddress" : "7-11 Quai André Citroën",
                     "postcode" : "75015"
                    }
        }, 
        {
         "hair" : "red",
         "name" : "henry",
         "address" : {
                      "city" : "Toulouse",
                      "streetAddress" : "2 Place Pierre Potier",
                      "postcode" : "75"
                     }
        }], 
    "SecondList" : [ 
        {
            "hair" : "blond",
            "name" : "Henry",
            "address" : {
                "city" : "Paris",
                "streetAddress" : "165 Rue de la Tour",
                "postcode" : "75017"
            }
        }
    ],
    "updated" : ISODate("2019-04-12T15:02:08.011Z")
} 

`

我想将“名称”作为索引,但是我不知道FirstList和SecondList可以持续多长时间。

我的第一个问题是知道是否有可能,如果可以,我是否应该使用类似的东西:

dbCollection.collection.create_index(name, unique=unique)

非常感谢

0 个答案:

没有答案