spring-mongodb

Is there way to check correctness of mongoDB connection?

核能气质少年 提交于 2021-02-20 00:41:27
问题 In my spring boot application i use spring-boot-starter-data-mongodb:2.1.3 to get coonection for MongoDB. I have some properties file to config mongoDB: spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=database If i set incorrect host name ( spring.data.mongodb.host=incorrect host ) or port my application starts successfully. But i want that application to fail as same as when i set host name with wrong format ( spring.data.mongodb.host=hxxt:/

Spring MongoDB mapping OAuth2Authentication

泪湿孤枕 提交于 2021-02-19 08:01:20
问题 I'm writing my own implementation of TokenStore (org.springframework.security.oauth2.provider.token.TokenStore) using MongoDB. There seems to be some problem with converting/mapping of the object in the database back to Java object. Anyone have a clue how I could solve this? org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate org.springframework.security.authentication.UsernamePasswordAuthenticationToken using constructor NO_CONSTRUCTOR with arguments

How to select between dates Spring data MongoDB using @Query

人盡茶涼 提交于 2021-02-19 06:53:05
问题 I'm using Spring data with MongoDB and i need to find between actual day and 7 days ahead. I have create repsoitories with @Query annotation and don't like to user Criteria class. Do you have some idea how to user between with @Query? thanks in advance. 回答1: You can try below query. Using @Query annotation @Query(value = "{'date':{ $lt: ?0, $gt: ?1}}") List<SomeClass> findByDateBetween(Instant from, Instant to); Or Using repository supported keywords List<SomeClass> findByDateBetween(Instant

How to select between dates Spring data MongoDB using @Query

青春壹個敷衍的年華 提交于 2021-02-19 06:52:09
问题 I'm using Spring data with MongoDB and i need to find between actual day and 7 days ahead. I have create repsoitories with @Query annotation and don't like to user Criteria class. Do you have some idea how to user between with @Query? thanks in advance. 回答1: You can try below query. Using @Query annotation @Query(value = "{'date':{ $lt: ?0, $gt: ?1}}") List<SomeClass> findByDateBetween(Instant from, Instant to); Or Using repository supported keywords List<SomeClass> findByDateBetween(Instant

How to select between dates Spring data MongoDB using @Query

纵饮孤独 提交于 2021-02-19 06:52:09
问题 I'm using Spring data with MongoDB and i need to find between actual day and 7 days ahead. I have create repsoitories with @Query annotation and don't like to user Criteria class. Do you have some idea how to user between with @Query? thanks in advance. 回答1: You can try below query. Using @Query annotation @Query(value = "{'date':{ $lt: ?0, $gt: ?1}}") List<SomeClass> findByDateBetween(Instant from, Instant to); Or Using repository supported keywords List<SomeClass> findByDateBetween(Instant

How to call MongoDB addFields in Spring Mongo?

萝らか妹 提交于 2021-02-11 14:41:44
问题 I have the following type of object in my MongoDB { ..., "name": { "en": "...", "am": "...", "ru": "..." }, ... } Now I want to run the following query using Spring Data Mongo db.categories.aggregate({$addFields: {'name': '$name.am'}}) where the am part in $name.am is the locale of the name, hence it must be dynamic. I looked through the MongoTemplate API, and as far as I found, there is no support of addFields operation. Is there any way to achieve this? 回答1: You need to implement

How project DBRef on Spring MongoDB Aggregation?

 ̄綄美尐妖づ 提交于 2021-02-08 08:45:20
问题 I have the following aggregation done in a MongoDB shell to get the number of alerts of each type for each user: db.getCollection('alerts').aggregate( { $unwind:"$son" }, { $group: { _id:{ son: "$son", level: "$level" }, count: { $sum: 1 } } }, { $group: { _id:{ son: "$_id.son" }, alerts: { $addToSet: { level: "$_id.level", count: "$count" }} } } ) I have translated it to Spring Data MongoDB as follows: TypedAggregation<AlertEntity> alertsAggregation = Aggregation.newAggregation(AlertEntity

How to add a json in a nested array of a mongodb document using Spring?

五迷三道 提交于 2021-02-02 10:01:06
问题 Document stored in mongodb: { "CNF_SERVICE_ID":"1", "SERVICE_CATEGORY":"COMMON_SERVICE", "SERVICES":[{ "SERVICE_NAME":"Authentication Service", "VERSIONS":[{ "VERSION_NAME":"AuthenticationServiceV6_3", "VERSION_NUMBER":"2", "VERSION_NOTES":"test", "RELEASE_DATE":"21-02-2020", "OBSOLETE_DATE":"21-02-2020", "STATUS":"Y", "GROUPS":[{ "GROUP_NAME":"TEST GROUP", "CREATED_DATE":"", "NODE_NAMES":[ "" ], "CUSTOMERS":[{ "CUSTOMER_CONFIG_ID":"4", "ACTIVATION_DATE":"21-02-2020", "DEACTIVATION_DATE":"21

How to add a json in a nested array of a mongodb document using Spring?

别等时光非礼了梦想. 提交于 2021-02-02 09:58:16
问题 Document stored in mongodb: { "CNF_SERVICE_ID":"1", "SERVICE_CATEGORY":"COMMON_SERVICE", "SERVICES":[{ "SERVICE_NAME":"Authentication Service", "VERSIONS":[{ "VERSION_NAME":"AuthenticationServiceV6_3", "VERSION_NUMBER":"2", "VERSION_NOTES":"test", "RELEASE_DATE":"21-02-2020", "OBSOLETE_DATE":"21-02-2020", "STATUS":"Y", "GROUPS":[{ "GROUP_NAME":"TEST GROUP", "CREATED_DATE":"", "NODE_NAMES":[ "" ], "CUSTOMERS":[{ "CUSTOMER_CONFIG_ID":"4", "ACTIVATION_DATE":"21-02-2020", "DEACTIVATION_DATE":"21

@Document doesn't create a collection in spring boot application

假如想象 提交于 2021-01-29 06:33:48
问题 I have a simple spring boot rest application. Trying to create a collection using @Document annotation in spring data mongo db. I know spring framework creates a collection if the document is denoted with @Document annotation. Entity @Document("User") public class User { @Id private String Id; @Field("firstName") @TextIndexed private String firstName; @Field("lastName") @TextIndexed private String lastName; private String address; public String getId() { return Id; } public void setId(String