How to add indexes in mongoDB project with Morphia framework

…衆ロ難τιáo~ 提交于 2019-12-10 22:31:41

问题


i'm working on a gwt project, that uses mongoDB as database, and morphia framework to work with mongodb.

I already finished the basic dao of my classes and now i want to insert indexes in my classes to speedup the mongo searches.

I looked the morphia documentation, and i saw that haves a @Indexed that makes this, but i don't know how to really use the index in a search. The morphia will automatically use the index?

Does anyone have a good example of index in a real project ? (the hello world examples of mongodb site doesn't help to much)

== EDIT ==

Is recommended insert index only in embed fields ?


回答1:


Mongodb will automatically use indexes so that isn't handled by morphia. You should index fields that you would commonly use for queries, for example:

Post:

{
    title : "My title", // indexed
    content : "My long long long long loooooong content" // Not indexed
}

In the simple post document shown above you see that the title field is indexed because a blog engine commonly searches over titles instead of contents plus the content will use a lot of your RAM so it might not fit in memory. That might no be the best example but it shows the main idea.

I suggest you to read the indexes link.



来源:https://stackoverflow.com/questions/7518878/how-to-add-indexes-in-mongodb-project-with-morphia-framework

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