mongorepository

MongoRepository @Query Failed to parse string as a date

∥☆過路亽.° 提交于 2020-01-15 12:15:37
问题 First of all, my issue is searching Collecttions in MongoDB via Spring JPA (MongoRepository). My Object: { "_id" : ObjectId("5c78e1f447f39c2eacb229d7"), "lab" : "xxx", "type" : "Holiday", "description" : "Lunar New Year", "start_date" : ISODate("2019-02-04T02:37:42.152Z"), "end_date" : ISODate("2019-02-08T06:37:42.152Z"), "all_day" : true, "_class" : "xxx.Event" } i can do as my wish in Mongo query as: db.getCollection('event').find({"start_date" : {$gte :ISODate( "2019-02-03T02:37:42.152Z")

Write custom query in mongodb repository

杀马特。学长 韩版系。学妹 提交于 2020-01-05 13:08:15
问题 I am writing custom query in mongo repository like this : public interface AuthenticationTokenRepository extends MongoRepository<AuthenticationToken, String> { AuthenticationToken save(AuthenticationToken token); AuthenticationToken findByToken(String token); @Query("{'user.username' : ?0}") AuthenticationToken findByUserId(String username); } But when i tried to findout AuthenticationToken by id then it is not working. @Query("{'user._id' : ?0}") AuthenticationToken findByUserId(String

Write custom query in mongodb repository

我只是一个虾纸丫 提交于 2020-01-05 13:08:12
问题 I am writing custom query in mongo repository like this : public interface AuthenticationTokenRepository extends MongoRepository<AuthenticationToken, String> { AuthenticationToken save(AuthenticationToken token); AuthenticationToken findByToken(String token); @Query("{'user.username' : ?0}") AuthenticationToken findByUserId(String username); } But when i tried to findout AuthenticationToken by id then it is not working. @Query("{'user._id' : ?0}") AuthenticationToken findByUserId(String

how to show query while using query annotations with MongoRepository with spring data

泄露秘密 提交于 2019-12-30 01:36:18
问题 I'm using MongoRepository in spring boot to access mongo: public interface MongoReadRepository extends MongoRepository<User, String> { @Query(value = "{$where: 'this.name == ?0'}", count = true) public Long countName(String name); } and it could work, but i wonder know the exactly query it accessing mongo how to do that? i try to adding some config at properties like below: logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG logging.level.org.springframework.data.mongodb

Spring MongoRepository @Query JSONParseException

懵懂的女人 提交于 2019-12-25 16:47:23
问题 I have the following MongoDB entities: public class Player { @Id private String id; private String username; private int rating; private boolean active; } public class Match { @Id private String id; @DBRef private Player playerOne; @DBRef private Player playerTwo; } I try to get all Player's matches. It means that e.g I have current player and matches list should be returned for matches when playerOne == current player or playerTwo == current player . I used MongoRepository for this: public

How to get data from two collections in spring using Mongotemplate or MongoRepository

坚强是说给别人听的谎言 提交于 2019-12-25 03:15:53
问题 I have started working with spring and mongodb few months ago. Till now I din't get how to fetch data from multiple collection using Mongotemplate or MongoRepository. I have two collections Person and Contacts.now I want to fetch list of Customer along with Contacts. Customer is having the is is _id and Contact is having the relation id is customerId So how can i get the customer contact details of the data. 回答1: Your data needs de-normalization, think the MongoDB way. You need to store

'Couldn't find PersistentEntity for type class' exception in Spring boot MongoRepository

对着背影说爱祢 提交于 2019-12-12 12:30:28
问题 In here I have configured two databases in mongodb. As described in this tutorial (link). So basically I override the MongoDataAutoConfiguration and MongoProperties implementations. The property yml file : spring: autoconfigure: exclude: org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration mongodb: primary: host: 127.0.0.1 port: 27017 database: db_admin_crm secondary: host: 127.0.0.1 port: 27017 database: lead_forms MultipleMongoProperties class : @Data @ConfigurationProperties

MongoRepository get only specific field as result

*爱你&永不变心* 提交于 2019-12-11 17:33:54
问题 i am using Mongodb in Spring Web. And use MongoRepository to CRUD I had: Collection: User Later, i had to create a Group. because i shouldn't and can't embedded User into Group. I create new collection as SQL name: GroupUser. In here, i use: @Field("groupId") private String groupId; @DBRef private User user; this will help to query list user in Group (query data and auto get User's content) But as i want to get the list User's Id. Normally, in SQL we can do like: select user.id from GroupUser

MongoDB Projection on embedded document field with mongoTemplate

霸气de小男生 提交于 2019-12-11 15:22:57
问题 In my java application i want retrieve a field of an embedded document. This is my pojo: My User.class public class User implements Comparable<User> { @Id private String username; private String ownerFirstname; private String ownerLastname; @DBRef @CascadeSave @JsonInclude(JsonInclude.Include.NON_NULL) private Role role; } Role.class @Document @JsonDeserialize(using = RoleDeserializer.class) public interface Role { String getId(); void setId(String id); } Society.class @Document(collection =

MongoRepository dynamic queries

◇◆丶佛笑我妖孽 提交于 2019-12-10 23:32:43
问题 I have the following problem. Lets say I have the following model object: class Person { String id; String firstName; String lastName; Map<String, String> properties; } In the properties map, you can insert any kind of property, there are no constrains. The above object is saved in a MongoDB which looks like this: public interface PersonRepo extends MongoRepository<Person, String> { } When a person is saved into the repository the Map<String, String> properties is flatten up. As an example,