开发者

MongoDb Index/Find on List of Lists

I'm using the C# mongodb d开发者_如何学Goriver to serialize a Dictionary into an embedded document. The embedded document looks something like:

"Lookup" : [[1234, {
    "Name" : "bob",
    "Age" : 25,
  }], [4567, {
    "Name" : "fred",
    "Age" : 31,
  }]]

Is it possible to create an index just on the "key" (i.e. 1234, 4567 etc) of the list? I've created an index on Lookup but I'm not sure what it's created an index on.

I'm guessing it's indexed the whole document because the query:

find ( {"Lookup" : { "$in" : [1234] } } )

Doesn't match anything.

Thanks,


You should change your structure to look something like this:

"Lookup" : [
    {key:1234,  value:{
      "Name" : "bob",
      "Age" : 25,
    }},
    {key: 4567, value: {
      "Name" : "fred",
      "Age" : 31,
    }}
]

Then you could index {"Lookup.key": 1} and it will do what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜