MongoDB + Spring:按文本@Query搜索

时间:2016-01-11 15:45:41

标签: java spring mongodb mongodb-query

使用MongoDB + Spring + MongoRepository我希望按照MongoDB文档显示文本进行查询。

我改编了代码:

db.users.find({ $text: { $search: "xxxxx"}});

要:

@Query("{'$text':{'$search':?0}}")
List<User> findBySearchText(String searchText);

我猜是正确的。但控制台告诉我,我必须索引我想要使用的字段(@TextIndexed)。所以我做到了。

控制台仍然抱怨多个错误导致我有一个主体'POJO',其中有更多'POJO'等待主体。有帮助吗?试图将内部POJOS作为新集合,并将其对应的字段编入索引:

 exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" , "createdCollectionAutomatically" : true , "numIndexesBefore" : 1 , "errmsg" : "exception: bad index key pattern { personalInformation.mobilePhone: \"text\", personalInformation.phone: \"text\", personalInformation.nif: \"text\", personalInformation.address: \"text\", personalInformation.population._id: \"text\", personalInformation.population.name: \"text\", personalInformation.population.fatherId: \"text\", personalInformation.population.provinceId: \"text\", personalInformation.town._id: \"text\", personalInformation.town.name: \"text\", personalInformation.town.fatherName: \"text\", personalInformation.postalCode: \"text\", personalInformation.censusPopulation._id: \"text\", professionalExperiences.toYear: \"text\",  
complementaryInformation.languages._id: \"text\", complementaryInformation.languages.name: \"text\", complementaryInformation.languages.readLevel: \"text\", complementaryInformation.languages.wroteLevel: \"text\", complementaryInformation.languages.spokeLevel: \"text\", complementaryInformation.ownCar: \"text\", professionalPreferences._id: \"text\", professionalPreferences.profession._id: \"text\", professionalPreferences.profession.value: \"text\", professionalPreferences.job._id: \"text\", professionalPreferences.job.value: \"text\", followPreference.serviceGuidance: \"text\", followPreference.serviceBusinessAdvice: \"text\" }: Index key pattern too large." , "code" : 67 , "ok" : 0.0}

0 个答案:

没有答案