Display mongodb index contents

♀尐吖头ヾ 提交于 2020-01-03 18:55:29

问题


After building an index, I'd like to view the contents of the index. Taking an example for illustration from the MonboDB docs:

{ "_id" : ObjectId("..."),
"name" : "Warm Weather",
"author" : "Steve",
"tags" : [ "weather", "hot", "record", "april" ] }

Then an index on the tags field would have these values:

{ tags: "weather" }
{ tags: "hot" }
{ tags: "record" }
{ tags: "april" }

So, I want to run a command, say, db.weather._tags_.find() to display said values.

Question: Does such a shell command exist? Or is there a way to do this in the C++ driver?


回答1:


@user1883451

What you have given example is of hash index, mongodb internally stores B-Tree index.

so example you have given is not always correct, mongodb end-up storing in that way in some case, but not always. [It is fine to understand it in oversimplified way]

  1. shell is client, and it does not show "internal on how index is stored"
  2. driver is mainly interacting with server (oversimplified), it is also not having any idea about how stuff is stored.

A)how to view mongodb index

Best start is to take mongo source code and start playing with it.

https://github.com/mongodb/mongo/tree/master/src/mongo/db/ files with index* https://github.com/mongodb/mongo/tree/master/src/mongo/db/ files with btree*

B)i assume you are trying to do just for learning purpose. If you are having any specific query, why you want to do that shoot out the query.

PS : 1. there is more code and less doc about internals and source code. 2. you can join http://groups.google.com/group/mongodb-dev




回答2:


@ranman Yes, that I use. I'd like to peek into the index itself to see why, say, a query is not being used. I love getting my hands on the bits and bytes and characters, as it were, to increase my understanding of what is happening under the hood. – user1883451 1 hour ago

In that case, you should look at query optimiser and related internals.



来源:https://stackoverflow.com/questions/13751078/display-mongodb-index-contents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!