开发者

Get the hit row in MongoDb

开发者 https://www.devze.com 2023-04-08 05:03 出处:网络
Let us say we have the next JSON structure: { { name:\"FirstComponent\", items:[ { Caption:\"Item1\", Value:\"1\"

Let us say we have the next JSON structure:

{
   {
      name:"FirstComponent",
      items:[
         {
            Caption:"Item1",
            Value:"1"
         },
         {
            Caption:"Item2",
            Value:"3"
         },
         {
            Caption:"Item3",
            Value:"2"
         }
      ]
   }
}

Let us say we query for the item with value "2". {"items.Value":"2"} and we would get the whole document back. What I want to have is an index of subdocument it hit on, it would be nice from my scenar开发者_JAVA技巧io.

Is there a way to get some indication on which is the first document which hit the search?


No, that wouldn't make sense: where would it store the index in the document it returns to you?

You need to just scan the array again in C# to find the index if you really need it.

0

精彩评论

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

关注公众号