MongoDB - index an internal list of objects

前端 未结 1 819
时光取名叫无心
时光取名叫无心 2021-01-23 07:37

Assume the following data structure in MongoDB:

{
    \"_id\" : \"Bob Blocker\",
    \"ratings\" : {
        \"771206753\" : 1
    },
    \"prevalence\" : 1
}


        
相关标签:
1条回答
  • 2021-01-23 07:51

    You can't index dynamic keys and indexing ratings would index the whole object as a blob so you don't want to do that either.

    It may work better to rework your schema to:

    {
        "_id" : "Bob Blocker",
        "ratings" : [
            {id: "771206753", value: 1}
        ],
        "prevalence" : 1
    }
    

    and then index 'ratings.id'.

    0 讨论(0)
提交回复
热议问题