开发者

How to add indexes in mongoDB project with Morphia framework

开发者 https://www.devze.com 2023-04-07 08:54 出处:网络
i\'m working on a gwt project, that uses mongoDB as database, and morphia framework to work with mongodb.

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 ?


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.

0

精彩评论

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

关注公众号