spring-data-mongodb

Multi-tenant mongodb database based with spring data

隐身守侯 提交于 2020-01-06 14:05:21
问题 I would like to make my web application that is using mongodb and spring-data multitenat. Basically I would like to replicate all my entities(collections) into different databases. Then (based on some rule as for example the user that is logged in the system) I want to store some entity instance (document) into the right database. For example I have a Service Called DBNameProviderService.getDbName() that dynamically returns me the name of the database. How can I use this service to

How to use the same parameter for multiple conditions

百般思念 提交于 2020-01-05 06:37:39
问题 I'm trying to compare a value with multiples fields with Spring-Data-MongoDB 1.10.0, I'm using @Query because the nested document is an Object with dynamic fields. But if I use the same identifier like ?5 in all the conditions, I got an error: exception="com.mongodb.util.JSONParseException: { companyType: "SPONSOR", companyId: 6710890, delivered: false, createdAt: { $gt: { "$date" : "2019-09-01T03:00:00.000Z"}, $lt: { "$date" : "2019-09-26T02:59:59.999Z"} }, $or:[ {requestPayload

How to use the same parameter for multiple conditions

孤街醉人 提交于 2020-01-05 06:37:07
问题 I'm trying to compare a value with multiples fields with Spring-Data-MongoDB 1.10.0, I'm using @Query because the nested document is an Object with dynamic fields. But if I use the same identifier like ?5 in all the conditions, I got an error: exception="com.mongodb.util.JSONParseException: { companyType: "SPONSOR", companyId: 6710890, delivered: false, createdAt: { $gt: { "$date" : "2019-09-01T03:00:00.000Z"}, $lt: { "$date" : "2019-09-26T02:59:59.999Z"} }, $or:[ {requestPayload

Spring Mongo nested inner query

被刻印的时光 ゝ 提交于 2020-01-05 03:59:10
问题 Trying to update an inner array document. There are three levels of the nested array. I am able to remove till the second level but not able to update the third level { "id":"Test", "name":"Test", "sections":[ { "sectionname":"Example1", "sectionroles":["test1", "test2", "test3"], "subcategory":[ { "Value":"demo", "ValueId":"123333333333", "sectionroles":["test1", "test2", "test3"], }, { "Value":"Example2", "Value":"6577544333333", "sectionroles":["test1", "test2", "test3"], } ] } I am able

MongoDB Spring data comparison between fields

蹲街弑〆低调 提交于 2020-01-04 14:23:12
问题 I'm trying to simply do a comparison between my fields but it doesn't seems to work with spring data : query.addCriteria(Criteria.where("active").gt("limit")); Active and limit are 2 fields of my collection, and I wand to display all fields that exceed the limit. This limit is different for each item so I cannot do gt(200) for example... There is anyway to do that ? 回答1: You can fall back to your java driver and issue a $where query: DBObject obj = new BasicDBObject(); obj.put( "$where",

How to use Mongo with Spring Data without ObjectId

六眼飞鱼酱① 提交于 2020-01-03 13:00:49
问题 I have an existing mongo database in which ids (_id) are persisted as plain Strings.. This is sample data in Mongo DB: { "_id" : "528bb0e2e4b0442f1479f1b4", "schoolId" : "URDLKYLFJXLWJGR193778316742298", "surname" : "Lewis", "admissionNumber" : "0347", "firstName" : "Martins" } I have a Java object which is of the form: public class Student { @Id private String id; private String schoolId; private String surname; private String admissionNumber; private String firstName; } With Getters and

How to use Mongo with Spring Data without ObjectId

旧巷老猫 提交于 2020-01-03 13:00:43
问题 I have an existing mongo database in which ids (_id) are persisted as plain Strings.. This is sample data in Mongo DB: { "_id" : "528bb0e2e4b0442f1479f1b4", "schoolId" : "URDLKYLFJXLWJGR193778316742298", "surname" : "Lewis", "admissionNumber" : "0347", "firstName" : "Martins" } I have a Java object which is of the form: public class Student { @Id private String id; private String schoolId; private String surname; private String admissionNumber; private String firstName; } With Getters and

junit test cases using embed mongodb de.flapdoodle.embed.mongo

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 04:16:06
问题 I wanted to setup mongodb junit environment with flapdoodle and I got a java.io.IOException when it tries to download the mongodb archive. I am using: spring-data-mongodb: 1.6.1.RELEASE de.flapdoodle.embed.mongo 1.47.3 org.springframework: 4.0.3.RELEASE I am getting following error: de.flapdoodle.embed.process.exceptions.DistributionException: java.io.IOException: Could not open inputStream for http://downloads.mongodb.org/win32/mongodb-win32-i386-3.0.2.zip Caused by: java.net

How do I expose a new REST method to through a Spring Data MongoDB repository with ALPS/HATEOAS metadata?

帅比萌擦擦* 提交于 2020-01-02 08:47:28
问题 How do I expose a new method in a MongoRepository extension class to the generated REST API and include the same ALPS/HATEOAS metadata, links etc. I have the usual Spring Data MongoDB repository: public interface CollectionRepository extends Repository<Collection, String> { // Simple queries Collection findFirstByName(@Param("name") String name); } Now I want to add another method and have it integrate into the generated Repository REST API so that it is included in the {repository}

MongoDB unique indexes disallow overwrite

一笑奈何 提交于 2020-01-02 08:34:13
问题 I have created an index with unique=true on one of the fields in my Mongo document. This works as expected - it disallows duplicates by overwriting the existing entry. I would like to disallow overwrites, and instead get an error or exception when an attempt is made to insert a duplicate. Is there any way to do this? How would I do this with Spring Data MongoDB? 回答1: By adding WriteConcern=SAFE to the MongoTemplate configuration, I was able to get exceptions when the "unique=true" constraint