Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9097615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:09:34+00:00 2026-06-17T00:09:34+00:00

I have some problem with Morphia. Could someone help me? I am writing web-project

  • 0

I have some problem with Morphia.
Could someone help me?

I am writing web-project on Spring + MongoDB about movies and celebrities.
I have entity class Genre:

@Entity(value="genres")
public class Genre implements IGenre {

    @Id
    @Indexed
    private ObjectId id;

    @Indexed
    private String name;

    private String description;

    private long quantity;

    private Set <IMovie> movies;

    //getters and setters

}

And entity class Movie:

@Entity(value="movies")
public class Movie implements IMovie {

    @Id
    @Indexed
    private ObjectId id;

    @Indexed
    private String originalTitle;

    private String year;

    private Set <IGenre> genres;

    // getters and setters

}

I have 30 genres. And for example one of them: Comedy.
Also I have 250 000 comedies.
And now I want to do movie pagination by genre = comedy.
How I can get only 20 records from all comedies.
If I use @Embedded or @Reference annotation I will still get the entire list at once. And it’s to big for use it in controllers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:09:36+00:00Added an answer on June 17, 2026 at 12:09 am

    You should change your data schema for doing such a query. The schema you use has a circular dependency, in your Genre entity you are holding Movies entity and in movies you hold Genre. Also holding all of the movies according to genre is not easy to query. If I were you I would use such a schema.

    @Entity(noClassnameStored = true) // you wouldn't have any problem when you change the class name or package of your class if you don't store the classname through this annotation
        public class Movie implements IMovie {
    
            @Id
            @Indexed
            private ObjectId id;
    
            @Indexed
            private String originalTitle;
    
            private String year;
    
            private Set <String> genres; // unique identifier of the genres instead of embedding the whole genre entity
    
            // getters and setters
    
        }
    

    So having such a schema, you can retrieve the movies having a particular genre by writing a simple $in query through genres field. Example query for your case:

    datastore.find(Movie.class).field("genres").in(Lists.newArrayList("comedy")).limit(20).asList;
    

    In the below web-page of mongo you can find suggestions about how to design your schema according to diffrerent scenarios.

    http://docs.mongodb.org/manual/core/data-modeling/#data-modeling-patterns-and-examples

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem with this mongoid. It's my first time to use mongoDB,
I have some problem with CompletionService. My task: to parse parallely for about 300
I have some problem about operator overloading. I looked everywhere but couldn't find a
I have some problem with writing a Method in the template pattern style. But
I have some problem with IoC - Unity. I made a simple web app.
I have some problem in my project. I want to delete my file from
I have some problem to find oop information about my problem in scala, peraphs
I have some problem with my project: def get_timein(self, cr, uid, ids, context={}): obj
I have some problem writing postgres functions in C++ while following the guides for
I have some problem with my android project! I have created a preferences intent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.