spring-data-mongodb

Aggregation sum in Spring Data MongoDB

心已入冬 提交于 2019-12-21 06:42:47
问题 I have MongoDB Page and Post collections. Each page document has field postIds which is array of post Ids (String objects). I want to use aggregation to count number of posts (=number of elements in array postIds) for each page. I wrote Mongo Shell aggregation function which returns exactly what I want: db.page.aggregate([ {$unwind : '$postIds'}, {$group : {_id: '$_id', 'sum': { $sum: 1}}} ]) and it returns this result: { "_id" : "3", "sum" : 3 } { "_id" : "2", "sum" : 3 } This means that

Spring Data - MongoDB indexing DBRef

独自空忆成欢 提交于 2019-12-21 03:57:35
问题 I'm using spring-data-mongodb-1.2.0.RELEASE. I have two classes A and B where B has a reference to A and it is annotated with @DBRef. Class A: @Document(collection = "a") public class A { @Id public String id; /** The TicketGrantingTicket this is associated with. */ @Field public String name; public A(String id, String name) { this.id = id; this.name = name; } } Class B: @Document(collection = "b") public class B { @Id public String id; @Field public String name; @DBRef @Indexed public A a;

Using conditional operator in a spring mongo [duplicate]

一曲冷凌霜 提交于 2019-12-20 07:37:56
问题 This question already has answers here : How to use $cond operation in Spring-MongoDb aggregation framework (2 answers) Closed last year . Following in my Mongo query {$project:{ id:"$_id", login:"$login", firstName: "$firstName", lastName:"$lastName", email:"$email", deactivateFlag:"$deactivateFlag", lastActivity:"$lastActivity", company :"$organization.name", RoleName :"$organization.roles.roleName", isMatchingRoles: { $eq: [ "$organization.roles.orgRoleId","$userOrgMap.roleId" ] } } }, {

Spring mongo repository slice

跟風遠走 提交于 2019-12-20 07:19:04
问题 I am using spring-sata-mongodb 1.8.2 with MongoRepository and I am trying to use the mongo $slice option to limit a list size when query, but I can't find this option in the mongorepository. my classes look like this: public class InnerField{ public String a; public String b; public int n; } @Document(collection="Record") punlic class Record{ public ObjectId id; public List<InnerField> fields; public int numer; } As you can see I have one collection name "Record" and the document contains the

Spring utilizing Mongo implementation over JPA

馋奶兔 提交于 2019-12-20 06:29:10
问题 I am fairly new to the Spring Framework and have been having some trouble setting up the project I am currently working on. I need to be able to connect to two different databases one being MongoDB and the other being MSSQL. I am using JPA to connect to the MSSQL. The problem that I am encountering is that it appears to be trying to make calls to the Mongo database when I want it to make calls to the MSSQL and I'm not really sure how to tell it what to read from. I have seen the posts

Spring Data-MongoDb Options for aggregation method

北慕城南 提交于 2019-12-20 03:29:44
问题 How can i set " allowDiskUse " option in aggregation method in spring data-mongodb framework ? 回答1: The core aggregation abstraction in Spring Data MongoDB is - as the name suggests - Aggregation . It exposes a fluent API to build up a pipeline using aggregation operations. As of version 1.6.0.M1 the Aggregation class has a ….withOptions(…) method to be used like this: Aggregation aggregation = newAggregation(…) // build up pipeline in here .withOptions(newAggregationOptions().allowDiskUse

Sort documents in collections while fetching

泄露秘密 提交于 2019-12-20 02:29:16
问题 I have a collection called at MongoDB called resource. It has the following documents: { "_id" : "Abb.e", "_class" : "Resource", "resourceEmail" : "test1@test.com" } { "_id" : "Dasd.tt", "_class" : "Resource","resourceEmail" : "test2@test.com" } { "_id" : "Bbb.rr", "_class" : "Resource", "resourceEmail" : "test3@test.com" } At Java code,I list them as follows: MongoOperations mongoOperations = mongoConfiguration.getMongoTemplate(); List<Resource> resourceList = mongoOperations.findAll

Storing a JSON schema in mongodb with spring

天涯浪子 提交于 2019-12-19 19:44:23
问题 I am new to Spring data and mongodb. I have a JSON object which represents a JSON Schema and I need to store that in mongodb using spring data. But the issue with JSON schema is the structure of JSON Schema is dynamic; for example below are two valid JSON schema with completely different structure. { "type": "object", "properties": { "name": { "type": "string", "minLength": 10 }, "age": { "type": "integer" } }, "required": [ "name", "age" ] } { "type": "array", "items": { "type": "object",

Spring Data MongoDB 4.0 transactions support

旧巷老猫 提交于 2019-12-19 11:49:15
问题 MongoDB 4.0 are going to introduce transactions support with ACID guarantees. Does Spring Data MongoDB already supports the transactions in MongoDB and if no, when this awesome feature will be available. I really need it, taking into account the following issue - MongoDB schema design in order to support application horizontal scaling 回答1: Does Spring Data MongoDB already supports the transactions in MongoDB Spring Data Lovelace M3 (2.1.0.M3) supports synchronous transaction for MongoDB v4.0,

Streaming the result of an aggregate operation using spring-data-mongodb

房东的猫 提交于 2019-12-19 09:27:15
问题 I am using spring-data-mongodb and I want to use a cursor for an aggregate operation. MongoTemplate.stream() gets a Query, so I tried creating the Aggregation instance, convert it to a DbObject using Aggregation.toDbObject() , created a BasicQuery using the DbObject and then invoke the stream() method. This returns an empty cursor. Debugging the spring-data-mongodb code shows that MongoTemplate.stream() uses the FindOperation , which makes me thinkspring-data-mongodb does not support