Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the difference between Spring Data's MongoTemplate and MongoRepository?
    primarykey
    data
    text
    <p>I need to write an application with which I can do complex queries using spring-data and mongodb. I have been starting by using the MongoRepository but struggled with complex queries to find examples or to actually understand the Syntax. </p> <p>I'm talking about queries like this:</p> <pre><code>@Repository public interface UserRepositoryInterface extends MongoRepository&lt;User, String&gt; { List&lt;User&gt; findByEmailOrLastName(String email, String lastName); } </code></pre> <p>or the use of JSON based queries which I tried by trial and error because I don't get the syntax right. Even after reading the mongodb documentation (non-working example due to wrong syntax).</p> <pre><code>@Repository public interface UserRepositoryInterface extends MongoRepository&lt;User, String&gt; { @Query("'$or':[{'firstName':{'$regex':?0,'$options':'i'}},{'lastName':{'$regex':?0,'$options':'i'}}]") List&lt;User&gt; findByEmailOrFirstnameOrLastnameLike(String searchText); } </code></pre> <p>After reading through all the documentation it seems that <code>mongoTemplate</code> is far better documented then <code>MongoRepository</code>. I'm referring to following documentation:</p> <p><a href="http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/" rel="noreferrer">http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/</a> </p> <p>Can you tell me what is more convenient and powerful to use? <code>mongoTemplate</code> or <code>MongoRepository</code>? Are both same mature or does one of them lack more features then the other?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload