spring-mongo

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 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

UnsatisfiedDependencyException when creating MongoTemplate bean

你离开我真会死。 提交于 2020-08-20 11:33:32
问题 Using the Mongobee for Migration with spring mongo plugins { id 'org.springframework.boot' version '2.3.1.RELEASE' id 'io.spring.dependency-management' version '1.0.9.RELEASE' id 'java' } group = 'fete.bird' version = '0.0.1-SNAPSHOT' sourceCompatibility = '14' compileJava { options.compilerArgs += ["--enable-preview"] } repositories { mavenCentral() } ext { set('springCloudVersion', "Hoxton.SR6") } dependencies { implementation 'org.springframework.boot:spring-boot-starter'

Spring Mongo DB @DBREF

筅森魡賤 提交于 2020-02-29 12:50:16
问题 This is my MongoDb structure, db.user.find(); user: { "name" : "KSK", "claim" : [objectId("52ffc4a5d85242602e000000"),objectId("52ffc4a5d85242602e000001")] } claim: [ { "_id" : "52ffc4a5d85242602e000001", "claimName" :"XXXX" }, { "_id" : "52ffc4a5d85242602e000000", "claimName" :"YYY" } ] My Entity class is: @Document(collection="user") public class User{ @Id private String id; private String name; @DBRef private List<Claim> claim; // setter and getter } Claim Class: @Document(collection=

Spring Mongo DB @DBREF

本小妞迷上赌 提交于 2020-02-29 12:50:08
问题 This is my MongoDb structure, db.user.find(); user: { "name" : "KSK", "claim" : [objectId("52ffc4a5d85242602e000000"),objectId("52ffc4a5d85242602e000001")] } claim: [ { "_id" : "52ffc4a5d85242602e000001", "claimName" :"XXXX" }, { "_id" : "52ffc4a5d85242602e000000", "claimName" :"YYY" } ] My Entity class is: @Document(collection="user") public class User{ @Id private String id; private String name; @DBRef private List<Claim> claim; // setter and getter } Claim Class: @Document(collection=

Spring mongo aggregation filter with $and, $in and $eq conditions

和自甴很熟 提交于 2020-01-10 06:11:06
问题 { "Field1": "ABC", "Field2": [ { "Field3": "ABC1","Field4": "REVIEWED","Field5":"True" }, { "Field3": "ABC2","Field4": "APPROVED","Field5":"True" }, { "Field3": "ABC3","Field4": "REJECTED","Field5":"True" }, { "Field3": "ABC4","Field4": "APPROVED","Field5":"False" } ] } I want to fetch APPROVED,REVIEWED and True record ie. { "Field1": "ABC", "Field2": [ { "Field3": "ABC1","Field4": "REVIEWED","Field5":"True" }, { "Field3": "ABC2","Field4": "APPROVED","Field5":"True" } ] } following mongo

Spring Data MongoRepository save causing Duplicate Key error

若如初见. 提交于 2020-01-06 06:49:09
问题 Here is the Entity: @Document @Data public class ApplicationUser { private String name; @Indexed(unique = true) private String email; private String organization = null; // other fields } I fetch this user using their email and then change their name. I use the autowired instance of ApplicationUserRepository. ApplicationUser applicationUser = applicationUserRepository.findByEmail("abc@gmail.com"); applicationUser.setName("John Doe 2"); Then I try to update this entity again in the database:

How to merge two matching objects from different array into one object?

社会主义新天地 提交于 2020-01-03 03:23:10
问题 I have a situation where I have got one result from aggregation where I am getting data in this format. { "_id" : ObjectId("5a42432d69cbfed9a410e8ad"), "bacId" : "BAC0023444", "cardId" : "2", "defaultCardOrder" : "2", "alias" : "Finance", "label" : "Finance", "for" : "", "cardTooltip" : { "enable" : true, "text" : "" }, "dataBlocks" : [ { "defaultBlockOrder" : "1", "blockId" : "1", "data" : "0" }, { "defaultBlockOrder" : "2", "blockId" : "2", "data" : "0" }, { "defaultBlockOrder" : "3",

How to add orderby using @query in mongodb repository

左心房为你撑大大i 提交于 2020-01-02 03:23:05
问题 I want to add orderby to the following repository method in mongodb with spring. I tried in various methods, but didnt work public interface StageRepository extends MongoRepository<Stage, String> { @Query("{$and: [ { 'categoryId': { $eq: ?0 } }, { 'isDeleted': { $eq: ?1 } } ]}") public List<Stage> findByCategoryIdAndIsNotDeleted(String categoryId, Boolean deleted); } I want to add orderby 'order' in the query. Not sure how to do it. 回答1: You can do like : @Query("{$and: [ { 'categoryId': {