spring-data-mongodb

How to apply update using Filtered positional operator with arrayFilters

狂风中的少年 提交于 2019-11-27 19:37:47
问题 I am running on Mongodb 3.6, with mongo driver 3.4.3 and spring data mongo 1.5.10. Below is the structure of my document { "_id": 12345, "_class": "com.example.ProductRates", "rates": [ { "productId": NumberInt(1234), "rate": 100.0, "rateCardId": NumberInt(1), "month": NumberInt(201801) }, { "productId": NumberInt(1234), "rate": 200.0, "rateCardId": NumberInt(1), "month": NumberInt(201802) }, { "productId": NumberInt(1234), "rate": 400.0, "rateCardId": NumberInt(2), "month": NumberInt(201803)

How to use $cond operation in Spring-MongoDb aggregation framework

不问归期 提交于 2019-11-27 15:10:39
I have an aggregation pipeline which includes a project like this: $project: { start: { $cond: { if: { $eq: ["$start", "EARLY"] }, then: "$deltastart.start", else: "$deltastart.end" } },... },... which works fine in mongo shell. How to express this using the Aggregation framework in Spring-Mongodb? I have seen ProjectionOperationBuilder, ExpressionProjectionOperationBuilder types but not an example how to use them... any suggestions? If using the current Spring Data release which has support for the $cond operator via the $project pipeline, then this can be converted to (untested): import

How to I get Spring-Data-MongoDB to validate my objects?

好久不见. 提交于 2019-11-27 14:02:21
I have a very simple Spring Boot application that uses Spring-Data-Mongodb All I want to do is set a JSR-303 validation rule that says the object I'm saving must have a username. I read that JSR-303 was added to spring-data-mongodb in version 1.1 so I assumed that when I save an object it's validated but this isn't the case. Does anyone have a simple example setup that shows how this works? My User pojo looks like public class User { @Id private String id; @NotNull(message = "User Name is compulsory") private String userName; private String password; public User() {} public String getId() {

What's the difference between Spring Data MongoDB and Hibernate OGM for MongoDB?

て烟熏妆下的殇ゞ 提交于 2019-11-27 10:30:38
问题 I have not used Spring Data before but I've used Hibernate ORM a number of times for MySQL based application. I just don't understand which framework to choose between the two for a MongoDB based application. I've tried searching for the answer but I can't find the answer which does a comparison between the two in a production environment. Has anyone found problems working with these two frameworks with MongoDB ? 回答1: Disclaimer: I am the lead of the Spring Data project, so I'll mostly cover

How to use dynamic schema in spring data with mongodb?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 08:58:25
Mongodb is a no-schema document database, but in spring data, it's necessary to define entity class and repository class, like following: Entity class: @Document(collection = "users") public class User implements UserDetails { @Id private String userId; @NotNull @Indexed(unique = true) private String username; @NotNull private String password; @NotNull private String name; @NotNull private String email; } Repository class: public interface UserRepository extends MongoRepository<User, String> { User findByUsername(String username); } Is there anyway to use map not class in spring data mongodb

Mongo how to $lookup with DBRef

对着背影说爱祢 提交于 2019-11-27 08:03:16
I have a trouble(/(ㄒoㄒ)/~~). Suppose that collection A is { "_id" : ObjectId("582abcd85d2dfa67f44127e1"), "bid" : [ DBRef("B", ObjectId("582abcd85d2dfa67f44127e0")), DBRef("B", ObjectId("582abcd85d2dfa67f44127e1")) ] } and Collection B: { "_id" : ObjectId("582abcd85d2dfa67f44127e0"), "status" : NumberInt(1), "seq" : NumberInt(0) }, { "_id" : ObjectId("582abcd85d2dfa67f44127e1"), "status" : NumberInt(1), "seq" : NumberInt(0) } I don't know how to $lookup the 'bid'. I tried db.A.aggregate( [ {$unwind: {path: "$bid"}}, {$lookup: {from: "B", localField: "bid", foreignField: "_id", as: "bs"}}, ] )

Missing class org.springframework.objenesis.ObjenesisStd

守給你的承諾、 提交于 2019-11-27 07:44:33
问题 I am trying to use Spring Data for MongoDB. I am using full text search feature of MongoDB, and wanted to try Spring Data annotations for text index fields ( @TextIndexed ). This feature is available in 1.6.0.BUILD-SNAPSHOT of Spring Data MongoDB. I am trying to setup simple application context in Spring and to run simple JUnit test. However my application context loading fails since I changed 1.5.1.RELEASE to 1.6.0.BUILD-SNAPSHOT. The error which I am getting is below: Caused by: org

Configure Multiple MongoDB repositories with Spring Data Mongo

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 06:52:41
问题 I have 2 Mongodb databases connected to a Spring Boot app with 2 MongoTemplate-s: mongoTemplate (the default bean name, connects to default db) mongoAppTemplate (connects to another database on run-time) I have a lot of MongoRepository-s that use mongoTemplate but I also want to create some that would use mongoAppTemplate. How can I configure 2 MongoRepository-s to use different MongoTemplate -s with Java configuration ? I found a way to do it with XML (link below), but I really want to keep

MongoDB: Not getting correct result using $geoWithin operator

青春壹個敷衍的年華 提交于 2019-11-27 06:33:01
问题 I am using $geoWithin for circle, and i am not getting expected result. There are two collections,one for users and second for items . I am setting radius and coordinates for item. so i have to find a users within that coordinates and radius. User collection { "_id" : NumberLong(25287), "_class" : "com.samepinch.domain.user.User", "name":"XYZ", "location" : [ 74.866247, 31.63336 ] } Item collection { "_id" : NumberLong(46603), "itemName" : "Chandigarh", "categoryName" : "TRAVELLING",

Spring-data-mongodb connect to multiple databases in one Mongo instance

喜夏-厌秋 提交于 2019-11-27 05:19:48
问题 I am using the latest spring-data-mongodb (1.1.0.M2) and the latest Mongo Driver (2.9.0-RC1). I have a situation where I have multiple clients connecting to my application and I want to give each one their own "schema/database" in the same Mongo server. This is not a very difficult task to achieve if I was using the driver directly: Mongo mongo = new Mongo( new DBAddress( "localhost", 127017 ) ); DB client1DB = mongo.getDB( "client1" ); DBCollection client1TTestCollection = client1DB