Skip to content
Advertisement

Tag: spring-data-mongodb

Convert nested map fields to snake case

how to convert all the nested fields of the following object rendered as json to snake_case? Given it’s read as a org.bson.Document, jackson object mapper won’t work as it’s designed for POJOs and it’s not possible to have POJOs here as the records are schema-less Answer It can be easily done by adding a custom key serializer to SimpleModule, then

How to count array elements properly with multiple aggregation in Spring Data MongoDB?

I need to create advanced aggregation using Spring Data MongoDB having model like that: pom.xml Cities collection: Libraries collection: Books collection: Depending on the context of the user, I have to return cities with count of libraries and books in the city that can be filtered based on startsWith() or like() principle. Assuming that I have 2 libraries in one

How to get list of data containing count of a field using Aggregation and Criteria in Spring Boot with MangoDB

Requirement: documents-bookdata collection may have multiple objects with same bookPublisherName but different bookName. Means multiple books can have same publisher so need to extract count of books per publisher . Model class: Response format pojo Response Format Answer This requirement can also be done logically ..like get the list of DocumentsBookdata using findAll and than filter it using loop and

Spring Data MongoDB 4.0 transactions support

MongoDB 4.0 are going to introduce transactions support with ACID guarantees. Does Spring Data MongoDB already supports the transactions in MongoDB and if no, when this awesome feature will be available. I really need it, taking into account the following issue – MongoDB schema design in order to support application horizontal scaling Answer Does Spring Data MongoDB already supports the

Change or override default Behavior of Mongorepository.save(document)

Is there any way to intercept or change the document before MongoRepository.save(e) updates it? I am trying to push a subproperty inside and array in a document. I have tried to manipulate DBObjects by implementing converter(using custom converter) but the $push operation did not work over there. I think to make it work I have to implement something like mongoOperation.update(dbObjectMatch,dbObjectUdate).

Spring Data MongoDB Annotation @CreatedDate isn’t working, when ID is assigned manually

I’m trying to use auditing to save dateCreated and dateUpdated in my objects, but since I set ID manually, there’s some additional work. Following Oliver Gierke’s suggestion in DATAMONGO-946 I’m trying to figure out how to correctly implement it. As original poster in Jira task above, I’ve downloaded example from here https://github.com/spring-guides/gs-accessing-data-mongodb.git and modified it a bit: and and a

Advertisement