spring-data-mongodb

Spring Data mongo to insert null values to DB

风流意气都作罢 提交于 2019-12-05 00:33:27
问题 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 name; //Getters and setters including hashcode and equals } my address is null here , after inserting the record in the collection, the data is populated with only age and name i know that mongodb treats null value and noKey as the same thing, but my requirement is to even

Mongodb select all fields group by one field and sort by another field

自古美人都是妖i 提交于 2019-12-04 21:23:45
问题 We have collection 'message' with following fields _id | messageId | chainId | createOn 1 | 1 | A | 155 2 | 2 | A | 185 3 | 3 | A | 225 4 | 4 | B | 226 5 | 5 | C | 228 6 | 6 | B | 300 We want to select all fields of document with following criteria distict by field 'chainId' order(sort) by 'createdOn' in desc order so, the expected result is _id | messageId | chainId | createOn 3 | 3 | A | 225 5 | 5 | C | 228 6 | 6 | B | 300 We are using spring-data in our java application. I tried to go with

Collection based multi tenancy in spring data mongo

喜你入骨 提交于 2019-12-04 20:02:57
I am starting a MULTI-TENANT project in spring data mongodb. After reading this post , collection per tenant is a pretty decent approach in mongodb. So how can I achieve this in Spring Data Mongo? Apparently, There's no out-of-box solution provided, but I thought I could tweak MongoTemplate by overriding determineCollectionName method but I assume its not a public nor protected method for purpose. However, I set up database per tenant approach very easily by extending SimpleMongoDbFactory and using LocalThread variable by following the tips provided here . So, the questions are: Is there any

Insert DBObject into MongoDB using Spring Data

。_饼干妹妹 提交于 2019-12-04 19:52:28
问题 I tried to insert the following DBObject into MongoDB using Spring Data: BasicDBObject document = new BasicDBObject(); document.put("country", "us"); document.put("city", "NY"); mongoTemplate.insert(document); where mongoTemplate is my Spring template (org.springframework.data.mongodb.core.MongoTemplate). When executing, I get: Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: No Persitent Entity information found for the class com.mongodb.BasicDBObject at org

Spring Data query over two documents

故事扮演 提交于 2019-12-04 19:24:46
I have an m:n connection in my MongoDB, MessageUserConnection is the class between User and Message. Now I will get all MessageUserConnections where MessageUserConnection#confirmationNeeded is true, read is false and Message#receiveDate is not older than the last week. Is there any possibility to do this with Spring Data? Thanks a lot! public class MessageUserConnection { @Id private String id; @DBRef private User userCreatedMessage; @DBRef private Message message; private Boolean confirmationNeeded; private Boolean read; } public class Message { @Id private String id; private String title;

Customizing Spring Data repository bean names for use with multiple data sources

旧巷老猫 提交于 2019-12-04 18:39:23
问题 I have a project that utilizes Spring Data (MongoDB in this instance) to interact with multiple databases with the same schema. What this means is that each database utilizes the same entity and repository classes. So, for example: public class Thing { private String id; private String name; private String type; // etc... } public interface ThingRepository extends PagingAndSortingRepository<Thing, String> { List<Thing> findByName(String name); } @Configuration @EnableMongoRepositories

Create Spring Data Aggregation from MongoDb aggregation query

有些话、适合烂在心里 提交于 2019-12-04 17:58:22
Can any one help me convert this mongoDB aggregation to spring data mongo? I am trying to get list of un-reminded attendee's email in each invitation document. Got it working in mongo shell, but need to do it in Spring data mongo. My shell query db.invitation.aggregate( [ { $match : {_id : {$in : [id1,id2,...]}}}, { $unwind : "$attendees" }, { $match : { "attendees.reminded" : false}}, { $project : {_id : 1,"attendees.contact.email" : 1}}, { $group : { _id : "$_id", emails : { $push : "$attendees.contact.email"} } } ] ) This is what I came up with, as you can see, it's working not as expected

storing a scanned (pdf,tiff,jpeg) file in MongoDB .

耗尽温柔 提交于 2019-12-04 17:45:25
I have to store a tiff(tag image file format) or pdf scanned file in mongodb that should be Text search able . like if we want to search "on base of text" it should be able to search . I am going to use .net mvc or java with mongodb . so how can i store this pdf file and then can retrieve from database . any suggestion will be appreciated . thanks shA.t You can store files by using MongoDb GridFs as described in this question and extract texts from a PDF file by using some features those described in this question . ;). HTH I think that you should save the files on file system of the server

spring-data mongodb custom implementation PropertyReferenceException

↘锁芯ラ 提交于 2019-12-04 17:15:09
问题 I'm trying to implement a custom query according to the Reference 4.4 Custom Implementations: http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/repositories.html What's the difference between Spring Data's MongoTemplate and MongoRepository? I'm doing this because I need special queries using mongoTemplate. The error I'm getting is a PropertyReferenceException. So it seems that spring-data is trying to auto-generate the query which I don't want. I want to use

MongoTemplate Criteria Query

不问归期 提交于 2019-12-04 13:29:42
问题 I'm generating a complicated Mongo query depending on multiple parameters. One of criterion that I want to make with Criteria helper class is: {"field1": {$exists: true, $ne: false}} I tried to make it with: Criteria.where("field1").is(Criteria.where("$ne").is(false).and("$exists").is(true)) But it generates: { "field1" : { $java : org.springframework.data.mongodb.core.query.Criteria@23864e60 } So, how to achieve the exact query that i need? I can't hardcode that query string, because these