Questions tagged [spring-mongo]

Don't use this tag. Use [spring-data-mongodb] instead.

Don't use this tag. Use instead.

251 questions
19
votes
3 answers

Spring Mongo DB @DBREF

I am having trouble writing code that would allow get a user and claim details in a straightforward way. This is my MongoDB structure, db.user.find(); user: { "name" : "KSK", "claim" :…
KSK
  • 636
  • 1
  • 9
  • 29
14
votes
5 answers

Mongodb $lookup in Spring data mongo

I'm a new Mongodb and I have a problem with $lookup with java spring. I would like to use this shell in Spring data db.NewFeed.aggregate([ { $match : {username : "user001"} }, { $lookup: { from:…
Anh Bui
  • 287
  • 1
  • 2
  • 9
14
votes
1 answer

MongoDB comparison operators with null

In MongoDB I would like to use $gt and $lt comparision operators where the value could be null. When the operators did not work with null, I looked for documentation but found none. In both cases it returned no documents (even though $ne, $gte,…
TryThis
  • 354
  • 2
  • 11
14
votes
2 answers

Spring mongodb get ID of inserted item after Save

I am working with Spring MongoDb. I create various entities using insert method: http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoOperations.html#insert-java.lang.Object- However, all methods…
Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
12
votes
0 answers

Spring Mongo DB @DBRef(lazy=true) - How to lazy Load

I have a model like the one below (assume as pseudo code ) class Student { @Id private String id; private String firstname; .....; @DBRef(lazy=true) private College college // getters and setters } class College { …
11
votes
3 answers

Spring boot 2.0.5.RELEASE and mongo 4.0 connection issues

I am following the Accessing Data with MongoDB tutorial on Spring web site I Installed Mongo DB server version 4 as a service Its authentication is working fine when I connect to it using a a client. I am facing the issue below: …
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
11
votes
2 answers

How to merge two matching objects from different array into one object?

I have a situation where I have got one result from aggregation where I am getting data in this format. { "_id" : ObjectId("5a42432d69cbfed9a410e8ad"), "bacId" : "BAC0023444", "cardId" : "2", "defaultCardOrder" : "2", "alias" :…
John Maclein
  • 1,034
  • 3
  • 13
  • 24
10
votes
3 answers

MongoDB $aggregate $push multiple fields in Java Spring Data

I have a mongo aggregate group query: db.wizard.aggregate( { $group: { _id: "$title", versions: { $push: {version:"$version", author:"$author", dateAdded:"$dateAdded"}} } }) I need this query in Java Spring-Data-MongoDB, my current…
quiros
  • 103
  • 1
  • 1
  • 4
10
votes
3 answers

Spring -Mongodb storing/retrieving enums as int not string

My enums are stored as int in mongodb (from C# app). Now in Java, when I try to retrieve them, it throws an exception (it seems enum can be converted from string value only). Is there any way I can do it? Also when I save some collections into…
gsagrawal
  • 2,900
  • 4
  • 27
  • 27
9
votes
2 answers

Spring Data mongo to insert null values to DB

I am using Spring data mongo to insert a record to Mongo, here is my code mongoTemplate.save(person,"personCollection"); Here is my person object public class Person implements Serializable { int age; String address; String…
user7077832
8
votes
1 answer

Disable create collection in spring data mongoDB

Can someone tell me how do I configure spring data mongoDB in such a way that it does not create a new collection(if it does not exist) but throws an exception while inserting a document?
Rakesh
  • 466
  • 3
  • 12
8
votes
3 answers

How to write union queries in mongoDB

Is it possible to write union queries in Mongo DB using 2 or more collections similar to SQL queries? I'm using spring mongo template and in my use case, I need to fetch the data from 3-4 collections based on some conditions. Can we achieve this in…
Punit
  • 324
  • 1
  • 4
  • 17
8
votes
1 answer

How to add orderby using @query in mongodb repository

I want to add orderby to the following repository method in mongodb with spring. I tried in various methods, but didnt work public interface StageRepository extends MongoRepository { @Query("{$and: [ { 'categoryId': { $eq: ?0 }…
CrazyProgrammer
  • 544
  • 8
  • 29
8
votes
2 answers

Difference between MongoFactoryBean and SimpleMongoDbFactory

I am setting up a MongoDB Spring MVC application and trying to use Service, DAO pattern. I read the Spring-Data-MongoDB refernce here, but I am not understanding what is the differnce between MongoFactoryBean and SimpleMongoDbFactory. What would be…
shams.haq
  • 703
  • 1
  • 6
  • 20
7
votes
1 answer

Aggregation Project Group By extracted day, month and year with Spring Data

To be direct, how do i do this: group._id = { year: { $year : [{ $subtract: [ "$timestamp", 25200000 ]}] }, month: { $month : [{ $subtract: [ "$timestamp", 25200000 ]}] }, day: { $dayOfMonth : [{ $subtract: [ "$timestamp", 25200000…
1
2 3
16 17