spring-mongo

Spring mongodb get ID of inserted item after Save

陌路散爱 提交于 2020-01-01 08:28:15
问题 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 return void . I need to return the ObjectId of the inserted document. What is the best way to get it? 回答1: This is pretty interesting and thought I would share. I just figured out the solution for this with the help of BatScream comment above: You

$filter inside $project MongoDB Using Spring Data

坚强是说给别人听的谎言 提交于 2019-12-29 08:15:31
问题 I have a subdocument that is an array of a parent document. "devices" In that array I've got a property which is a Date property. I want to find the parents documents who contains the child subdocuments by determinated date like this: { "_id" : ObjectId("5818fa596969a1339093a7da"), "fecha" : ISODate("2016-11-01T05:00:00.000Z"), "spot" : "5808e3926969a126c8365c94", "devices" : [ { "evaluationDate" : ISODate("2016-11-01T20:26:00.000Z"), "seenTimesCounter" : 0, "category" : "PRE_PASAJERO",

How to write union queries in mongoDB

﹥>﹥吖頭↗ 提交于 2019-12-12 05:27:57
问题 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 use case is that I need to fetch the data from 3-4 collections based on some conditions. Can we achieve this in a single operation? For example, I have a field named "circuitId" which is present in all 4 collections. Now, in searching operations, I need to fetch all the records from all the 4 collections wherever that field matches with given value. 回答1:

How to write Mongodb aggregation group pipeline on part of Date/Time(Year, month, day, hour) in Spring?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:25:35
问题 I need help in writing mongodb aggregation pipeline in spring. Here is a sample of my data on which I want to execute the query (Please note that the following data is a result of Match aggregation pipeline in spring which has conditions for the eventDate to match the range and eventName equals to 'A'): { "_id": ObjectId("1234567890"), "eventDate": ISODate("2017-01-29T03:56:04.297Z"), "eventName": "A" } { "_id": ObjectId("1234567890"), "eventDate": ISODate("2017-01-29T03:57:04.887Z"),

Use $stdDevSamp or $stdDevPop with Spring Mongo

对着背影说爱祢 提交于 2019-12-11 09:56:14
问题 I'd like to know how to implement a Standard Deviation aggregation Function to use in Spring Mongo Data. I Know Mongo DB 3.2 has a Standard Deviation aggregation function, but It isn't available in Spring Data. Could I use the Mongo's aggregation function? Thanks. 回答1: There is a distinct difference between "not available" and "no implemented helper method" , and that is the real case here. Just because there is no "helper" for implementing the $stdDevSamp or $stdDevPop operators, does not

MongoDB comparison operators with null

半腔热情 提交于 2019-12-09 02:56:22
问题 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, and $lte did return documents; meaning there were documents that were both equal to and not equal to null ). I would expect $gt to essentially operate like $ne (as the null type Mongo comarison order is so low) and $lt to return nothing for the same

MappingMongoConverter setMapKeyDotReplacement dont work

守給你的承諾、 提交于 2019-12-08 04:28:01
问题 My code following this link: How to customize MappingMongoConverter (setMapKeyDotReplacement) in Spring-Boot without breaking the auto-configuration? @Override @Bean public MappingMongoConverter mappingMongoConverter() throws Exception { DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(this.mongoDbFactory()); MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, this.mongoMappingContext()); converter.setCustomConversions(this.customConversions()); converter

Is Spring mongoTemplate thread safe?

孤者浪人 提交于 2019-12-07 12:49:57
问题 I define this Bean: <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> <constructor-arg name="mongoConverter" ref="mongoConverter" /> </bean> and i instantiate a mongoOprations using this Bean, now i want To know Is Spring mongoTemplate thread safe? 回答1: As per spring docs. Once configured, MongoTemplate is thread-safe and can be reused across multiple instances. For more details see section 5.4

Sharding with spring mongo

爷,独闯天下 提交于 2019-12-06 07:53:43
问题 I'm using mongoDB for storing and querying close to 50 mn records (Large Json files with no fixed schema), through a spring web application. Simple K-V pair based find queries run into a few seconds. I'm looking at ways to bring search time down to < 1s. Indexing doesn't work for me because of the nature of the files stored. I was looking at alternatives and came across sharding. However, I found no good tutorial explaining how to set up sharding for my existing spring-mongo application. Can

Is Spring mongoTemplate thread safe?

会有一股神秘感。 提交于 2019-12-05 18:41:07
I define this Bean: <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> <constructor-arg name="mongoConverter" ref="mongoConverter" /> </bean> and i instantiate a mongoOprations using this Bean, now i want To know Is Spring mongoTemplate thread safe? As per spring docs. Once configured, MongoTemplate is thread-safe and can be reused across multiple instances. For more details see section 5.4 来源: https://stackoverflow.com/questions/29913211/is-spring-mongotemplate-thread-safe