Questions tagged [spring-mongodb]

Do not use this. Use [spring-data-mongodb] instead.

Do not use this. Use instead.

422 questions
6
votes
1 answer

Mongodb aggregation project after lookup

I am doing MongoDB aggregation. I want to lookup two collections then project only desired field in nested array. Two collections to lookup: db.pitcher.find().pretty() { "_id" : ObjectId("59b22eeef224252e6c7eeaf6"), "userId" :…
Ricky Lee
  • 77
  • 1
  • 1
  • 4
6
votes
2 answers

Spring mongodb template saves in the same object

I have the model like following @CompoundIndexes(value = { @CompoundIndex(name = "catalog_idx", def = "{'code' : 1, 'brand' : 1}", unique = true) }) @Document(collection = Catalog.ENTITY) public class Catalog extends AbstractModel
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212
6
votes
2 answers

Morphia vs Spring Data Mongo

I am using Java language.I have to use ORM framework with MongoDb as Database.I have two options Morphia or Spring Data Mongo support.As far i am able to get details , it has been found Spring Data Mongo is better to use since: 1)It provides better…
Mohit Gupta
  • 215
  • 5
  • 7
6
votes
3 answers

How to get Count of aggregation query in spring mongo template

I'm using spring mongo template to run an agreegation query on mongodb. I'm wondering is there any way to find out the count of aggregation result in spring mongo template? Here is my Aggregation sample : Aggregation agg =…
Zhozhe
  • 403
  • 2
  • 5
  • 14
5
votes
3 answers

Spring Boot MongoDB Indexed with expireAfterSeconds to Auto delete Document does not work

I have a problem with the "time to live" settings in MongoDB. I created an Indexed Annotation in my Spring-Boot 2.0.2.RELEASE project in my Entity which represents my Document in the MongoDB. I set the "expireAfterSeconds" for testing to 15 seconds…
iSmo
  • 190
  • 3
  • 11
5
votes
0 answers

Query in Mongodb throws a org.springframework.data.mapping.MappingException

I am trying using mongoDB in spring. When I was trying to query the users with the function findUserByUserNamelike this: @Repository("usersDao") public class UserDaoImpl implements UserDao { @Autowired MongoTemplate mongoTemplate; …
david
  • 842
  • 2
  • 8
  • 25
5
votes
1 answer

Java to JSON serialization with Jackson PTH and Spring Data MongoDB DBRef generates extra target property

When serializing from Java to JSON, Jackson generates an extra target property for referenced entities when using the Spring Data MongoDB @DBRef annotation with lazy loading and Jackson’s polymorphic type handling. Why does this occur, and is it…
user9353951
5
votes
1 answer

Spring Boot - MongoDB - Inheritance

I'm running into something odd with inheritance and mongodbrepositories. I have the following: ` @Document public class Base { public String fieldA; } public class Derived extends Base { public String fieldB; } public interface…
Morrowyn
  • 149
  • 1
  • 1
  • 9
5
votes
1 answer

Usage of OffsetDateTime with Spring Boot and MongoDB results in MappingException

I am trying to set up a Spring Boot application with a MongoDB database. Here is an excerpt from the dependencies I have (in Gradle…
Bugra
  • 189
  • 2
  • 14
5
votes
3 answers

Spring mongodb add or update a list of documents

I have a list of records like [ {"id":"1", "name":"a", "user":"u1"}, {"id":"2", "name":"b", "user":"u1"}, {"id":"3", "name":"c", "user":"u1"} ] Now based on if an entry already exists or not in the database, it should either update or…
BiJ
  • 1,639
  • 5
  • 24
  • 55
5
votes
4 answers

How do you set WriteConcern using spring mongodb to ACKNOWLEDGED?

I want to set the WriteConcern in spring mongodb to acknowledged. Also, I'm wondering if this is the default value? I am using the spring.data.mongodb.uri in my application.properties so I don't have any mongo configuration class.
demig0d
  • 1,131
  • 1
  • 12
  • 24
5
votes
1 answer

Id field handling in Spring Data Mongo for child objects

I have been working in Spring Boot with the Spring Data MongoDB project and I am seeing behavior I am not clear on. I understand that the id field will go to _id in the Mongo repository per…
Rob Baily
  • 2,770
  • 17
  • 26
5
votes
1 answer

MongoTemplate: sum values of keys for documents matching a certain criterion

My following mongodb query works as expected db.importedDataItems.aggregate({ $match: { mobile: "1234567890" } }, { $group: { _id: 'mobile', calls: { $sum: '$calls' } } }) but even after referring to these…
Parth
  • 729
  • 8
  • 23
5
votes
1 answer

Aggregate via Spring MongoTemplate to get max value of a collection

I want to find users by most recent date (Assume the User object has a date field). The data is stored in MongoDB and accessed via a Spring MongoTemplate. Example of the raw data: {userId:1, date:10} {userId:1, date:20} {userId:2,…
paul
  • 12,873
  • 23
  • 91
  • 153
4
votes
1 answer

Spring boot Mongo on update: E11000 duplicate key error with @Version annotation

I have a Spring boot (v2.3.0.RELEASE) application with spring-data-mongodb (v3.0.0). Basically when I add @Version annotation in my document, the application fails when I am trying to update an existing document and the code is as follows: My…
1
2
3
28 29