spring-data-mongodb

Facet + Aggregate Query using ObjectId issue with Spring Data Mongo

北慕城南 提交于 2020-03-18 06:28:05
问题 I am developing Spring Boot + Spring Data Mongo . I am really struggling to public Page<EmployeeOut> getData(Pageable pageable) { ....... ....... MatchOperation matchStage = Aggregation.match(criteria); GroupOperation groupOp = Aggregation .group("firstName", "lastName", "email", "status", "id") .addToSet("department").as("department").addToSet("address").as("address"); ProjectionOperation projectStage = Aggregation.project("firstName", "lastName", "email", "status", "department", "address",

How to use $arrayElemAt operator in Spring Data MongoDB

谁说胖子不能爱 提交于 2020-03-06 04:25:30
问题 $arrayElemAt new in MongoDB version 3.2. db.users.aggregate([ { $project: { name: 1, first: { $arrayElemAt: [ "$favorites", 0 ] }, last: { $arrayElemAt: [ "$favorites", -1 ] } } } ]) 回答1: DATAMONGO-1536 is about to add $arrayElemAt and other missing aggregation operators to Spring Data MongoDB for the Ingalls release. Meanwhile you can provide your own AggregationExpression to create whatever operation is needed. For the above something like the following does the trick: project("name") //

How to use $arrayElemAt operator in Spring Data MongoDB

谁说我不能喝 提交于 2020-03-06 04:25:10
问题 $arrayElemAt new in MongoDB version 3.2. db.users.aggregate([ { $project: { name: 1, first: { $arrayElemAt: [ "$favorites", 0 ] }, last: { $arrayElemAt: [ "$favorites", -1 ] } } } ]) 回答1: DATAMONGO-1536 is about to add $arrayElemAt and other missing aggregation operators to Spring Data MongoDB for the Ingalls release. Meanwhile you can provide your own AggregationExpression to create whatever operation is needed. For the above something like the following does the trick: project("name") //

How are fields set on an entity by Spring Data MongoDB?

巧了我就是萌 提交于 2020-03-02 06:05:10
问题 I have a MongoRepository class public interface UserRepository extends MongoRepository<User, Long> { User findById(Long id); } and my Entity pojo looks like this @Document(collection = "user") class User { Long id; String name; Department department; … } When I call the findBy method, a User object is returned. I want to know how does Spring Data MongoDB converts DBObject to Java object. I was under the impression that Spring Data MongoDB uses some sort of mapper (Jackson?) under the hood

How are fields set on an entity by Spring Data MongoDB?

橙三吉。 提交于 2020-03-02 06:03:09
问题 I have a MongoRepository class public interface UserRepository extends MongoRepository<User, Long> { User findById(Long id); } and my Entity pojo looks like this @Document(collection = "user") class User { Long id; String name; Department department; … } When I call the findBy method, a User object is returned. I want to know how does Spring Data MongoDB converts DBObject to Java object. I was under the impression that Spring Data MongoDB uses some sort of mapper (Jackson?) under the hood

How to prevent Spring Data MongoDB from mapping id field as object id?

╄→гoц情女王★ 提交于 2020-03-01 03:35:45
问题 I have set up my own mechanism for assigning identities to my domain objects, and so when persisting them, there really isn't much value for me to keep track of what MongoDB assigns to them. However, I name the identity fields for my domain classes id because, well, it's concise and understandable. The problem is that, according to the documentation, Spring will automatically map this field to MongoDB's assigned ObjectID. How do I prevent this from happening without having to rename my id

How to prevent Spring Data MongoDB from mapping id field as object id?

▼魔方 西西 提交于 2020-03-01 03:34:47
问题 I have set up my own mechanism for assigning identities to my domain objects, and so when persisting them, there really isn't much value for me to keep track of what MongoDB assigns to them. However, I name the identity fields for my domain classes id because, well, it's concise and understandable. The problem is that, according to the documentation, Spring will automatically map this field to MongoDB's assigned ObjectID. How do I prevent this from happening without having to rename my id

How can I implement addFields mongoDB query in Java

断了今生、忘了曾经 提交于 2020-02-28 06:28:49
问题 I have found several example at StackOverFlow related to addFields in Aggregation. But no one implemented in Java. db.getCollection('myDocument').aggregate([ {$match : {"metaId.ref.uuid" : "d6112808-1ce1-4545-bd52-cf55bc4ed25e"}}, {$lookup: {from: "simple", localField: "someId.ref.uuid", foreignField: "uuid", as: "simple"}}, {"$unwind": "$simple"}, {"$addFields": { "metaId.ref.name" : "$simple.name" }} ]) I am not able to Implement In Java Correctly:-- Not getting proper procedure

How can I implement addFields mongoDB query in Java

末鹿安然 提交于 2020-02-28 06:28:24
问题 I have found several example at StackOverFlow related to addFields in Aggregation. But no one implemented in Java. db.getCollection('myDocument').aggregate([ {$match : {"metaId.ref.uuid" : "d6112808-1ce1-4545-bd52-cf55bc4ed25e"}}, {$lookup: {from: "simple", localField: "someId.ref.uuid", foreignField: "uuid", as: "simple"}}, {"$unwind": "$simple"}, {"$addFields": { "metaId.ref.name" : "$simple.name" }} ]) I am not able to Implement In Java Correctly:-- Not getting proper procedure

While saving a collection MongoDB is creating Index name which is too long and exceeds 127 bytes limit. How to solve this. can i disable indexing?

ε祈祈猫儿з 提交于 2020-02-21 10:45:14
问题 com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" , "createdCollectionAutomatically" : true , "numIndexesBefore" : 1 , "ok" : 0.0 , "errmsg" : "namespace name generated from index name \"NDS.ABCD_pre_import.$importabilityEvaluations.perNameResults.straightImportResults.resultPolContent_NOT_IN_CURRENT_USE.officialPolResultNameContentId\" is too long (127 byte max)" , "code" : 67} at com.mongodb.CommandResult.getException(CommandResult.java:76) at com.mongodb.CommandResult