spring-data-mongodb

Mongodb aggregation query to subtract and grouping of cumulative value

℡╲_俬逩灬. 提交于 2019-11-29 07:14:41
{ "_id" : ObjectId("58f5a22d22679039176d2ee8"), "MachineID" : NumberInt("1001"), "Timestamp" : ISODate("2017-04-18T07:01:01.000+05:30"), "Utilization" : NumberInt("63654480"), "RunStatus" : NumberInt("1"), "ProductsCount" : NumberInt("681350") }, { "_id" : ObjectId("58f5a22d22679039176d2ee9"), "MachineID" : NumberInt("1001"), "Timestamp" : ISODate("2017-04-18T07:02:02.000+05:30"), "Utilization" : NumberInt("63655480"), "RunStatus" : NumberInt("1"), "ProductsCount" : NumberInt("681370") }, { "_id" : ObjectId("58f5a22d22679039176d2eea"), "MachineID" : NumberInt("1001"), "Timestamp" : ISODate(

How to run js file in mongo using spring data

你离开我真会死。 提交于 2019-11-29 07:02:43
In mongo shell js file can be run using load command: load("path/to/file/file.js") How to do this using spring-data? Or any other way in Java. I've tried: BasicDBObject obj = new BasicDBObject(); obj.append( "$load" , "/path/file.js" ); CommandResult t=mongoTemplate.executeCommand(obj); and: obj.append( "$eval" , "load(\"/path/file.js\")" ); but it doesn't work. Here's the relevant section of the reference docs on how to work with scripts in Spring Data MongoDB. ScriptOperations scriptOps = template.scriptOps(); // Execute script directly ExecutableMongoScript echoScript = new

Java 8 Date/Time (JSR-310) types mapping with Spring Data MongoDB

只愿长相守 提交于 2019-11-28 21:37:09
I have simple document with Java 8 date/time fields @Document public class Token { private Instant createdAt; ... } that I want to persist with Spring Data MongoDB version 1.5. But fields of type java.time.Instant could not be de-serialized correctly because MappingMongoConverter lacks converters for java.time classes. In Spring 4 I found org.springframework.format.datetime.standard.DateTimeConverters with different Converter s including InstantToLongConverter and LongToInstantConverter declared as private static classes. How can I configure MongoTemplate to use them to map Instant fields to

How to disable spring-data-mongodb autoconfiguration in spring-boot

谁都会走 提交于 2019-11-28 21:02:27
问题 Has anyone tried disabling autoconfiguration for mongodb in spring-boot? I am trying out spring-boot with spring-data-mongodb; Using java based configuration; Using spring-boot 1.2.1.RELEASE, I import spring-boot-starter-web and its' parent pom for dependency management. I also import spring-data-mongodb (tried spring-boot-starter-mongodb as well). I need to connect to two different MongoDB servers. So I need to configure two sets of instances for mongo connection, MongoTemplate etc. I also

What's the difference between Spring Data MongoDB and Hibernate OGM for MongoDB?

孤者浪人 提交于 2019-11-28 17:29:34
I have not used Spring Data before but I've used Hibernate ORM a number of times for MySQL based application. I just don't understand which framework to choose between the two for a MongoDB based application. I've tried searching for the answer but I can't find the answer which does a comparison between the two in a production environment. Has anyone found problems working with these two frameworks with MongoDB ? Disclaimer: I am the lead of the Spring Data project, so I'll mostly cover the Spring Data side of things here: I think the core distinction between the two projects ist that the

Configure Multiple MongoDB repositories with Spring Data Mongo

百般思念 提交于 2019-11-28 12:07:46
I have 2 Mongodb databases connected to a Spring Boot app with 2 MongoTemplate-s: mongoTemplate (the default bean name, connects to default db) mongoAppTemplate (connects to another database on run-time) I have a lot of MongoRepository-s that use mongoTemplate but I also want to create some that would use mongoAppTemplate. How can I configure 2 MongoRepository-s to use different MongoTemplate -s with Java configuration ? I found a way to do it with XML (link below), but I really want to keep it all annotation based Spring-data-mongodb connect to multiple databases in one Mongo instance The

MongoDB: Not getting correct result using $geoWithin operator

心已入冬 提交于 2019-11-28 11:51:37
I am using $geoWithin for circle, and i am not getting expected result. There are two collections,one for users and second for items . I am setting radius and coordinates for item. so i have to find a users within that coordinates and radius. User collection { "_id" : NumberLong(25287), "_class" : "com.samepinch.domain.user.User", "name":"XYZ", "location" : [ 74.866247, 31.63336 ] } Item collection { "_id" : NumberLong(46603), "itemName" : "Chandigarh", "categoryName" : "TRAVELLING", "location" : { "_id" : null, "longitude" : 77.15319738236303, "latitude" : 28.434568229025803, "radius" : 29153

MongoDB $pull array 2 level

前提是你 提交于 2019-11-28 09:45:18
问题 I'm trying to pull an element in an array with e two level deep complexity My document : > db.users.find({ mail : 'titi@toto.fr'}).pretty() { "_class" : "bean.User", "_id" : ObjectId("52f504bb2f9dd91186211537"), "commandes" : [ { "adresse" : "15 rue de la soif", "codePostal" : "29200", "idCommande" : 1, "montantTotal" : 0, "nom" : "TOTO", "prenom" : "tata", "ville" : "Brest", "voyagesSouscrits" : [ { "idVoyage" : "123", "duree" : 1, "nbPersonnes" : 0, "villeDepart" : "Nantes", "prixVoyage" :

How to see the repository implementation generated by Spring Data MongoDB?

我的梦境 提交于 2019-11-28 09:15:52
When is the implementation for repositories generated by Spring Data? At compile time or runtime? Can I see the implementation repository implementation generated by Spring Data? tl;dr No, for a very simple reason: there's no code generation going on. The implementation is based on proxies and a method interceptor delegating the call executions to the right places. Details Effectively, a method execution can be backed by 3 types of code: The store specific implementation of CrudRepository . Have a look for types named Simple(Jpa|Mongo|Neo4|…)Repository (see the JPA specific one here ). They

How To Configure MongoDb Collection Name For a Class in Spring Data

江枫思渺然 提交于 2019-11-28 06:50:43
I have a collection called Products in my MongoDB database, which is represented by the interface IProductPrice in my Java code. The following repository declaration causes Spring Date to look to the collection db.collection: Intelliprice.iProductPrice . I want it to configure it to look in db.collection: Intelliprice.Products using an external configuration rather than putting an @Collection(..) annotation on IProductPrice . Is this possible? How can I do this? public interface ProductsRepository extends MongoRepository<IProductPrice, String> { } The only way you can currently achieve this is