title: Spring Data Mongo | Cannot authorize inserting into system.indexes documents without a string-typed
body: <p>I am facing problem while trying to create Spring Data Mongo Repository.</p>
  
  <p>Relevant code &amp; config.:-</p>
  
  <p>The model class:-</p>
  
  <pre><code>@Document(collection = "USER_DETAIL")
  public class UserDetail implements
          org.springframework.security.core.userdetails.UserDetails, Serializable {
  
      private static final long serialVersionUID = -2637223077307659181L;
  
      @Id
      private String id;
  
      @Indexed(dropDups = true, name = "usernameIndex", unique = true)
      private String username;
  
      private String fname;
      private String lname;
      private List&lt;UserRole&gt; authorities;
      private String password;
      private boolean accountNonExpired;
      private boolean accountNonLocked;
      private boolean credentialsNonExpired;
      private boolean enabled;
  
          // getter &amp; setters.
  }
  </code></pre>
  
  <p>Spring Data Repository class :-</p>
  
  <pre><code>public interface UserDetailsRepository extends
          MongoRepository&lt;UserDetail, String&gt; {
  
      /**
       * Find a user by its username.
       * 
       * @param username
       * @return
       */
      public UserDetail findByUsername(String username);
  }
  </code></pre>
  
  <p>Spring Java configuration :-</p>
  
  <pre><code>@Configuration
  @EnableMongoRepositories(basePackages = { "x.y.z.repository" })
  public class MongoRepositoryConfig {
  
      @Bean
      public MongoTemplate mongoTemplate() throws UnknownHostException {
          MongoTemplate mongoTemplate = new MongoTemplate(mongo(), "expunto");
          return mongoTemplate;
      }
  
      @Bean
      public Mongo mongo() throws UnknownHostException {
          MongoClient client = new MongoClient("localhost");
          return client;
      }
  
  }
  </code></pre>
  
  <p>Error :- <strong>Cannot authorize inserting into system.indexes documents without a string-typed \"ns\" field." , "code" : 13 , "n" : 0 , "ok" : 1.0}
      at com.mongodb.CommandResult.getException(CommandResult.java:77) ~[mongo-java-driver-2.11.4.jar:na]</strong></p>
  
  <p>Stacktrace :-</p>
  
  <pre><code>Caused by: com.mongodb.WriteConcernException: { "serverUsed" : "localhost/127.0.0.1:27017" , "connectionId" : 10 , "err" : "Cannot authorize inserting into system.indexes documents without a string-typed \"ns\" field." , "code" : 13 , "n" : 0 , "ok" : 1.0}
      at com.mongodb.CommandResult.getException(CommandResult.java:77) ~[mongo-java-driver-2.11.4.jar:na]
      at com.mongodb.CommandResult.throwOnError(CommandResult.java:110) ~[mongo-java-driver-2.11.4.jar:na]
      at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:102) ~[mongo-java-driver-2.11.4.jar:na]
      at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:142) ~[mongo-java-driver-2.11.4.jar:na]
      at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115) ~[mongo-java-driver-2.11.4.jar:na]
      at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:248) ~[mongo-java-driver-2.11.4.jar:na]
      at com.mongodb.DBApiLayer$MyCollection.createIndex(DBApiLayer.java:340) ~[mongo-java-driver-2.11.4.jar:na]
      at com.mongodb.DBCollection.createIndex(DBCollection.java:485) ~[mongo-java-driver-2.11.4.jar:na]
      at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.createIndex(MongoPersistentEntityIndexCreator.java:135) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
      at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.checkForAndCreateIndexes(MongoPersistentEntityIndexCreator.java:129) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
      at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.checkForIndexes(MongoPersistentEntityIndexCreator.java:121) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
      at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.onApplicationEvent(MongoPersistentEntityIndexCreator.java:105) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
      at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.onApplicationEvent(MongoPersistentEntityIndexCreator.java:46) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98) ~[spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333) ~[spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:307) ~[spring-data-commons-1.8.0.RELEASE.jar:na]
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:181) ~[spring-data-commons-1.8.0.RELEASE.jar:na]
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:141) ~[spring-data-commons-1.8.0.RELEASE.jar:na]
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67) ~[spring-data-commons-1.8.0.RELEASE.jar:na]
      at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.getEntityInformation(MongoRepositoryFactory.java:141) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
      at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.getTargetRepository(MongoRepositoryFactory.java:83) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:158) ~[spring-data-commons-1.8.0.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224) ~[spring-data-commons-1.8.0.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210) ~[spring-data-commons-1.8.0.RELEASE.jar:na]
      at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      ... 40 common frames omitted
  </code></pre>
  
  <p><strong>UPDATE</strong>:-</p>
  
  <p>Spring Data Mongo version - 1.5.0.RELEASE.
  Build system - Maven</p>
  
  <p>Thanks for your help.</p>