spring-data-mongodb

Java 8 Date/Time (JSR-310) types mapping with Spring Data MongoDB

倖福魔咒の 提交于 2019-12-18 01:16:33
问题 I have simple document with Java 8 date/time fields @Document public class Token { private Instant createdAt; ... } that I want to persist with Spring Data MongoDB version 1.5. But fields of type java.time.Instant could not be de-serialized correctly because MappingMongoConverter lacks converters for java.time classes. In Spring 4 I found org.springframework.format.datetime.standard.DateTimeConverters with different Converter s including InstantToLongConverter and LongToInstantConverter

ZonedDateTime with MongoDB

感情迁移 提交于 2019-12-17 19:20:40
问题 Trying to use ZonedDateTime with MongoDB . I'm able to save ZonedDateTime in MongoDB but when i look at the record it has so much unnecessary stuffs in there: > "timestamp" : { > "dateTime" : ISODate("2016-12-13T13:45:53.991Z"), > "offset" : { > "_id" : "-05:00", > "totalSeconds" : -18000 > }, > "zone" : { > "_class" : "java.time.ZoneRegion", > "_id" : "America/New_York", > "rules" : { > "standardTransitions" : [ > NumberLong(-2717650800) > ], > "standardOffsets" : [ > { > "_id" : "-04:56:02"

ZonedDateTime with MongoDB

ⅰ亾dé卋堺 提交于 2019-12-17 19:17:10
问题 Trying to use ZonedDateTime with MongoDB . I'm able to save ZonedDateTime in MongoDB but when i look at the record it has so much unnecessary stuffs in there: > "timestamp" : { > "dateTime" : ISODate("2016-12-13T13:45:53.991Z"), > "offset" : { > "_id" : "-05:00", > "totalSeconds" : -18000 > }, > "zone" : { > "_class" : "java.time.ZoneRegion", > "_id" : "America/New_York", > "rules" : { > "standardTransitions" : [ > NumberLong(-2717650800) > ], > "standardOffsets" : [ > { > "_id" : "-04:56:02"

Spring Data MongoDB and Bulk Update

ε祈祈猫儿з 提交于 2019-12-17 16:44:43
问题 I am using Spring Data MongoDB and would like to perform a Bulk Update just like the one described here: http://docs.mongodb.org/manual/reference/method/Bulk.find.update/#Bulk.find.update When using regular driver it looks like this: The following example initializes a Bulk() operations builder for the items collection, and adds various multi update operations to the list of operations. var bulk = db.items.initializeUnorderedBulkOp(); bulk.find( { status: "D" } ).update( { $set: { status: "I"

Spring Data MongoDB - Views, @CompoundIndex and annotation inheritance

匆匆过客 提交于 2019-12-14 03:34:44
问题 I'm running into an issue trying to leverage inheritance in combination with MongoDB views and @CompoundIndex . Say I have a collection items and a view of that collection called itemsView . I'm representing these entities in my models like so: @Document(collection = "items") @CompoundIndex(name = "view_active_available" def = "{active: 1, quantity: 1}") public class Item { // Adding index on collection that view definition will leverage } Then, for the view I want to extend the Item class so

ArrayIndexOutOfBoundsException while Spring save data to MongoDB

旧城冷巷雨未停 提交于 2019-12-13 19:18:19
问题 This qustion is separated from : Spring doesn't save object to MongoDB correctly I have SampleClass which has one field - TreeMap<String, TreeMap<String,String>> map . When I deploy application and run following code: SampleClass sample = new SampleClass(); mongo.save(sample, "SampleCollection"); //MongoOperations object I get following exception: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang

Group aggregation using spring data mongodb

左心房为你撑大大i 提交于 2019-12-13 18:58:06
问题 I tried to write a group aggregation query using the year value from a date object as a key, but for some reason I'm getting this exception. org.springframework.data.mapping.PropertyReferenceException: No property year(invoiceDate) Here is the mongo query which I'm trying to replicate: db.collection.aggregate([ { $match: { "status": "Active" } }, { $group: { "_id":{$year:"$invoiceDate"} } }, { $sort: { "_id" : -1 } } ]) And this is my Java implementation: Aggregation aggregation = Aggregation

Why does Spring Data MongoDB 1.5.2 fail a with NoSuchMethodError?

一曲冷凌霜 提交于 2019-12-13 14:33:23
问题 I can't seem to get the most basic MongoTemplate to initialize with spring-mongodb. Here's the relevant extract from my POM: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> <version>1.5.2.RELEASE</version> </dependency> My XML context setup looks like this: <mongo:db-factory id="mongoDbFactory" host="$

Cannot use Nested VariableOperators.mapItemsOf in Spring Data MongoDb

▼魔方 西西 提交于 2019-12-13 12:41:23
问题 I'm forced to use the aggregation framework and the project operation of Spring Data MongoDb . What I'd like to do is creating an array of object as a result of a project operation. Considering this intermediate aggregation result: { "processes": [ { "id": "101a", "assignees": [ { "id": "201a", "username": "carl93" }, { "id": "202a", "username": "susan" } ] }, { "id": "101b", "assignees": [ { "id": "201a", "username": "carl93" }, { "id": "202a", "username": "susan" } ] } ] } I'm trying to get

Spring throws ConverterNotFound for range search on date in MongoDB

馋奶兔 提交于 2019-12-13 07:45:31
问题 I'm trying to do a range search on DateTime data format. The dates are being stored in Joda's DateTime format in the MongoDB. When I do a FIND query for a data greater than a given date, the ConverterNotFoundException is being thrown. Could someone please share information on why the conversation of Date object is being done to DateTime (Joda) &how can I possibly resolve this? Exception org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from