Announcement Announcement Module
Collapse
No announcement yet.
Querying with MongoTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Querying with MongoTemplate

    I am running into an error when I try to query with MongoTemplate. The same query runs with no error when I go natively via the mongo java driver.

    Code snippet:
    Code:
    String query = "{'firstName':'John'}";
    mongoTemplate.find(new BasicQuery(String.format(query, arguments)), Applicant.class);
    Error:

    Code:
    SearchController - query: {'firstName':'John'}
    org.springframework.data.document.UncategorizedDocumentStoreException: ns name too long, max size is 128; nested exception is com.mongodb.MongoException: ns name too long, max size is 128
    	at org.springframework.data.document.mongodb.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:73)
    	at org.springframework.data.document.mongodb.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:1338)
    	at org.springframework.data.document.mongodb.MongoTemplate.execute(MongoTemplate.java:317)
    	at org.springframework.data.document.mongodb.mapping.MongoPersistentEntityIndexCreator.ensureIndex(MongoPersistentEntityIndexCreator.java:165)
    	at org.springframework.data.document.mongodb.mapping.MongoPersistentEntityIndexCreator.checkForIndexes(MongoPersistentEntityIndexCreator.java:102)
    	at org.springframework.data.document.mongodb.mapping.MongoPersistentEntityIndexCreator.onApplicationEvent(MongoPersistentEntityIndexCreator.java:75)
    	at org.springframework.data.document.mongodb.mapping.MongoPersistentEntityIndexCreator.onApplicationEvent(MongoPersistentEntityIndexCreator.java:52)
    	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
    	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303)
    	at org.springframework.data.mapping.BasicMappingContext.addPersistentEntity(BasicMappingContext.java:189)
    	at org.springframework.data.mapping.BasicMappingContext.addPersistentEntity(BasicMappingContext.java:128)
    	at org.springframework.data.document.mongodb.MongoTemplate.getEntityCollection(MongoTemplate.java:1288)
    	at org.springframework.data.document.mongodb.MongoTemplate.find(MongoTemplate.java:491)
    	at com.jrock.hsdemo.web.SearchController.index(SearchController.java:94)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Thread.java:680)
    Caused by: com.mongodb.MongoException: ns name too long, max size is 128
    	at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:136)
    	at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:157)
    	at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:141)
    	at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:225)
    	at com.mongodb.DBApiLayer$MyCollection.createIndex(DBApiLayer.java:310)
    	at com.mongodb.DBCollection.ensureIndex(DBCollection.java:368)
    	at org.springframework.data.document.mongodb.mapping.MongoPersistentEntityIndexCreator$2.doInCollection(MongoPersistentEntityIndexCreator.java:179)
    	at org.springframework.data.document.mongodb.MongoTemplate.execute(MongoTemplate.java:315)
    	... 40 more
    Digging through the stack trace, I see the template is trying to create an index at the time it is trying to issue a query. Why so?
    If at all an index needs to be created, how can I specify a shorter name for the index at query time to ensure I am not running into this error?

    Thanks.
Working...
X