I have a big entity I created in Play! framework in Java and I would like to retrieve only a specific field from the database using Morphia and MongoDB. The entity itself is very big and contains many fields, so I would like to improve the performance of my application by retrieving only one field from it.
I know it is possible but I can't figure out exactly how to do it...
Here are some of the fields I have in my class Shop
:
public String imagePath;
public String profileImagePath;
public String Motto;
@Reference
public Category primeCategory;
public boolean isOnline;
As you can see, the primeCategory
field is a Category
entity which I want to retrieve.
I saw something which suppose to achieve that in Morphia's website:
Datastore ds = null;
Shop shop = ds.createQuery(Shop.class).retrievedFields(true, "primeCategory").get();
I'm not sure what exactly do I'm getting here.
It would be great if someone could explain to me if this is the way and how exactly I should do it, as well as provide an example.
try this
Shop.createQuery().retrievedFields(true, "primeCategory").get()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With