spring-data-mongodb

Nullpointerexception at org.springframework.data.mongodb.core.convert.DefaultDbRefResolver.<c linit>(DefaultDbRefResolver.java:57)

匆匆过客 提交于 2019-12-11 01:57:03
问题 As I have looked for an answer to this exception, but didn't find it anywhere, I'll leave this post here for future reference. So if anyone else runs into this problem, you are welcome. I'm using the maven shade plugin to create a runnable jar together with org.springframework.data:spring-data-mongodb:1.4.0.RELEASE I was running into the exception in the title, after creating the jar and running it with java -jar Foo-0.0.1-SNAPSHOT.jar 回答1: And the answer: The error is here: https://github

QueryDSL for Mongo with Spring and gradle

我的梦境 提交于 2019-12-11 00:31:16
问题 How do I generate the predicate classes (Q* classes) with gradle? I want to use Q* classes for Mongo using Spring data. Spring documentation shows maven and ant versions but no gradle. Is there any plugin out there that I could use? 回答1: You can use the same approach is presented here Generating JPA2 Metamodel from a Gradle build script Just replace the Querydsl JPA APT processor with the Spring Mongodb processor. 回答2: There is an example in my project: spring-data-demo You will need to

Query failed with error code 13 and error message 'not authorized on [db] to execute command { find:

断了今生、忘了曾经 提交于 2019-12-11 00:11:51
问题 I am using the following Mongo 3.2.7 Spring 4.3.1 release I have created following user with the below privileges. > use admin switched to db admin > db.getUser("UserAdminNew") { "_id" : "admin.UserAdminNew", "user" : "UserAdminNew", "db" : "admin", "roles" : [ { "role" : "readWrite", "db" : "admin" }, { "role" : "root", "db" : "admin" }, { "role" : "readWrite", "db" : "NEWTest" } ] } In DB NEWTest I have the below mentioned collections > use NEWTest switched to db NEWTest > show collections

Spring Mongodb Timestamp Timezone Misleading

依然范特西╮ 提交于 2019-12-10 22:56:19
问题 I am using Spring Data MongoDB. When I save some records MongoDb doesn't save correctly my timestamp. Here is my timestamp field in Spring. @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private Date timestamp = new Date(); My MongoDB record. { "_id": ObjectId("5697a672ce2a8e5347d86afd"), "batteryLevel": 100, "beaconClass": 3, "beaconId": "dsadsa", "timestamp": ISODate("2016-01-14T13:45:22.702Z") } When I log to console my timezone and date I see it is correct. Eastern European Time Asia

Use multiple/different MongoTemplates with same Respository class

妖精的绣舞 提交于 2019-12-10 21:19:50
问题 I have a collection on three different mongo databases(same schema). So I have created a Repository for this. But is it possible that i can use different mongoTemplates(one for three different databases) but same repository class. I can create three different repository classes(one for each database), But I don't want to do this because the schema is the same on all three. Thanks 来源: https://stackoverflow.com/questions/38265818/use-multiple-different-mongotemplates-with-same-respository-class

How to process insert requests in Spring Data before adding them to MongoDB?

南笙酒味 提交于 2019-12-10 20:35:57
问题 after following the very useful tutorial at https://spring.io/guides/gs/accessing-mongodb-data-rest/ , I'm trying to create a link shortener app. I've coded an URL class (with id , longURL and hash attributes) and URLRepository class (for now, with just the findByHash method as shown in the demo). Please note that by "hash" I'm referring to a random short string generated by a method yet-to-be-implemented, not an actual hashing function like MD5. Just calls to a independent generateHash

spring-data-mongodb giving mongodb authentication exception

柔情痞子 提交于 2019-12-10 19:16:00
问题 I am using Mongodb 3.2.0 Mongo-Java-Driver 3.2.0 spring-data-mongodb 1.9.2 and referred to this link accessing-mongodb-with-authentication, and created user in myDb by logging as admin to admin database. db.createUser({user: "admin",pwd: "password",roles: [ { role: "readWrite", db: "myDb" } ]}); db.auth('admin','password'); db.grantRolesToUser("admin",[{ role: "dbAdmin", db: "myDb" }]) for setting up mongodb authentication the link example worked. The spring-data configuration is : <bean

Loading initial data at application startup with Spring Data MongoDB

試著忘記壹切 提交于 2019-12-10 18:14:13
问题 I use embedded MongoDB database in a development environment. It is setup empty at the application startup. I would like to load initial data which is needed for the application when the Spring context is setup. Is there a way in Spring Data MongoDB to point a JSON file(s) which would be loaded into a database (something like import.sql (hibernate.hbm2ddl.import_files) in Hibernate or @UsingDataSet in NoSql Unit)? 回答1: mongeez see wiki link for spring integration wiki 来源: https:/

MappingException: Ambiguous field mapping detected

*爱你&永不变心* 提交于 2019-12-10 18:10:09
问题 Using Spring boot 1.5.6.RELEASE. I have the following mongo document base class: @Document(collection="validation_commercial") public abstract class Tier { @Id private String id; @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private Date created; @Field("tran") private Tran tran; public Tier() { } public String getId() { return id; } public void setId(String id) { this.id = id; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created;

Why is WriteResultChecking set to NONE by default?

心已入冬 提交于 2019-12-10 17:33:41
问题 According to the Spring data mongodb documentation, the default behaviour of MongoTemplate is to not launch neither log any exception thrown by the underlying persistence layer (mongo driver). In fact, the documentation says: When in development it is very handy to either log or throw an exception if the com.mongodb.WriteResult returned from any MongoDB operation contains an error. It is quite common to forget to do this during development and then end up with an application that looks like