spring-data-mongodb

Does Spring Data MongoDB supports MongoDB 3.4 collation feature?

青春壹個敷衍的年華 提交于 2019-12-07 14:21:10
问题 Im using: spring-boot-starter-parent 1.5.1.RELEASE spring-data-mongodb 1.10.0.RELEASE MongoDB 3.4 I need to use and aggregation like: db.getCollection('person').aggregate([{$project:{firstName:1,lastName:1,sortName:{$concat:["$firstName"," ","$lastName"]}}},{$sort:{sortName:1}}],{collation:{locale:"es",strength:2}}) But I don't find how to use collation with spring-data-mongodb? Does anyone knows if Spring Data MongoDB actually supports collation new MongoDB 3.4 feature? If not, does are

MongoDB Java Driver creating Database and Collection

隐身守侯 提交于 2019-12-07 12:18:17
问题 i was testing how to create database and collection mongo java driver. MongoClient client = new MongoClient("localhost",27017); DB db = client.getDB("ow"); DBCollection collection = db.getCollection("documents"); collection.save(new BasicDBObject("_id",1)); collection.remove(new BasicDBObject("_id",1)); boolean result = db.collectionExists("documents"); assertTrue(result); assertNotNull(collection); client.close(); I would prefer to use createCollection method on the DB object, but found that

How to modeling when use Spring data mongo and Spring data elasticearch?

喜夏-厌秋 提交于 2019-12-07 10:25:14
问题 I want to use mongo and ElasticSearch in my projects, and I also like adopt Spring Data Mongo and Spring Data ElasticSearch, but both has their Repository and model specs, how to use them together? There are some options: Use the same model class for Mongo and ElasticSearch? @Document//from Spring Data Mongo @Document// from Spring Data ElasticSearch public class Book{ @Id//Spring Data Commons private String id; } But there are some mismatch in Spring Data Mongo and Spring Data ElasticSearch,

how to insert embedded document using spring data mongodb mongotemplate

拟墨画扇 提交于 2019-12-07 05:48:02
问题 I need to insert a new track into the existing event document following is my class structure class Event { String _id; List<Track> tracks; } class Track { String _id; String title; } My existing document is { "_id":"1000", "event_name":"Some Name" } document will look like after insertion { "_id":"1000", "event_name":"Some name", "tracks": [ { "title":"Test titile", } ] } How can i insert that track into my existing document using mongoTemplate spring data mongodb? 回答1: First, you have to

How to convert BigDecimal to Double in spring-data-mongodb framework

若如初见. 提交于 2019-12-07 05:11:15
问题 Spring Data MongoDB mapping by default converts BigDecimal to String. However, I want them to be converted as Double in mongodb. This is required for latter to make queries on this field in mongodb (comparison queries/aggregation queries). How can I reigster my own converter (BigDecimalToDouble / DoubleToBigDecimal) to do this? 回答1: Here's how you can add your own converters: <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref=

Spring Data MongoDB support bulk insert/save

纵饮孤独 提交于 2019-12-07 00:22:44
问题 I have been google for a while, not sure whether Spring Data MongoDB supports for bulk save. I need to save a collection of documents into mongo as atomic, either all saved or none saved. Can anyone share a link or some sample code for this? 回答1: When you do a save through MongoDB Java driver you can only pass a single document to MongoDB. When you do an insert, you can pass a single element or you can pass an array of elements. The latter is what will result in a "bulk insert" (i.e. single

Spring Data MongoDB Date between two Dates

为君一笑 提交于 2019-12-06 22:46:59
问题 i'm using Spring Data for MongoDB and got the following classes class A { List<B> b; } class B { Date startDate; Date endDate; } when i save an object of A it gets persisted like { "_id" : "DQDVDE000VFP8E39", "b" : [ { "startDate" : ISODate("2009-10-05T22:00:00Z"), "endDate" : ISODate("2009-10-29T23:00:00Z") }, { "startDate" : ISODate("2009-11-01T23:00:00Z"), "endDate" : ISODate("2009-12-30T23:00:00Z") } ] } Now i want to query the db for documents matching entries in b where a given date is

Spring Data Mongo - How to query by @DBRef field's id

烂漫一生 提交于 2019-12-06 21:14:46
问题 I am new to Spring Data Mongo so I must be doing something wrong because I can't manage to execute such a simple query. This is my model: @Document(collection="brands") public class Brand{ @Id private int id; private String name; ... //getters-setters } @Document(collection="models") public class Model{ @Id private int id; private String name; @DBRef private Brand brand; ... //getters-setters } I would like to get all models from a brand, so I implement the DAO as follows: @Repository public

how to use sum and condition in group using spring data mongodb aggregation

て烟熏妆下的殇ゞ 提交于 2019-12-06 16:06:54
db.test.aggregate( [ { $group: { _id: "$id", "total":{$sum: 1}, "live" : { $sum : {$cond : { if: { $eq: ["$status",A"]},then: 1, else: 0}}}, "chat_hrs" :{ $avg: { $subtract: [ "$end_time", "$start_time" ] } }}}]). Kindly help me to write springmvc coding to use mongodb aggregation for the above query. You can use the below aggregation pipeline. import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; import static org.springframework.data.mongodb.core.aggregation.ArithmeticOperators.*; import static org.springframework.data.mongodb.core.aggregation.ConditionalOperators

The value for annotation attribute PageableDefault.size must be a constant expression

梦想与她 提交于 2019-12-06 14:46:52
I already went through many links but did not find solution. Here is my code: @Value("${paging.default.pageSize}") public int pageSize; Controller method: @GetMapping() public ResponseEntity<Page<Employee>> getAllEmployee(@PageableDefault(size = pageSize) Pageable pageable) { return countryService.findAllCountries(pageParams, pageable); } The value for annotation attribute PageableDefault.size must be a constant expression 来源: https://stackoverflow.com/questions/56107812/the-value-for-annotation-attribute-pageabledefault-size-must-be-a-constant-expre