简体   繁体   中英

mongodb search indexing performance

I have a collection with thousands of documents each of which contains a string to be searched for. I would like to make an index for these strings like so:

index a "an apple"

index a "arbitrary value"

index s "something"

I think I will be able to improve the search performance if I create these indices so that when I search for 'something', I can only look up documents in the index 's'. I am new to database design and wonder if this is the right way to improve the performance of the queries with string values. Is there any better way to do this or does mongodb have a built in mechanism to achieve this kind of indexing? Please enlighten me.

You can create indexes based on the keys and not on the values.

  • Each document will have a default index created on the _id field.
  • You can also create compound Index, ie combining on or more fields
  • Creation of Index should be appropriate to your search, so that your search queries will be faster.

http://docs.mongodb.org/manual/indexes/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM