spring-mongodb

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;

Geospatial $near within current document field value

天大地大妈咪最大 提交于 2019-12-08 05:11:41
问题 Take this query: { 'location' : { '$near' : [x,y], '$maxDistance' : this.field } } I want to assign $maxDistance the value of the specified field from the current evaluated document. Is that possible? 回答1: Yes it's possible. You just use $geoNear instead. Beware the catches and read carefully. Presuming that your intent to is to store a field such as "travelDistance" to indicate on the document that any such searches must be "within" that supplied distance from the queried point to be valid.

Remove items from array of documents in Spring+Mongo

♀尐吖头ヾ 提交于 2019-12-02 07:27:21
I have a collection of documents like this in a mongo db : "_id" : ObjectId("592bc37c339e7a23788b4c7c"), "trips" : [ { "tripGcsId" : "5937f86e339e7a2a58ac3186", "tripCounter" : NumberLong(1283), "tripRef" : "hjkhjk" }, { "tripGcsId" : "5937f914339e7a2a58ac318b", "tripCounter" : NumberLong(1284), "tripRef" : "fjh" } ] and a method on the server side (Spring+Mongo): public List<String> removeTripObject( List<String> tripIds ) { Query query = Query.query( Criteria.where( "trips" ).elemMatch( Criteria.where( "tripGcsId" ).in( tripIds ) ) ); Update update = new Update().pullAll( "trips.tripGcsId",

Java to JSON serialization with Jackson PTH and Spring Data MongoDB DBRef generates extra target property

ⅰ亾dé卋堺 提交于 2019-12-01 20:18:56
问题 When serializing from Java to JSON, Jackson generates an extra target property for referenced entities when using the Spring Data MongoDB @DBRef annotation with lazy loading and Jackson’s polymorphic type handling. Why does this occur, and is it possible to omit the extra target property? Code Example @Document(collection = "cdBox") public class CDBox { @Id public String id; @DBRef(lazy = true) public List<Product> products; } @Document(collection = "album") public class Album extends Product

mongodb mongoTemplate get distinct field with some criteria

六眼飞鱼酱① 提交于 2019-11-30 19:15:16
My MongoDB json structure is { "_id" : "122134231234234", "name" : "Total_pop", "description" : "sales category", "source" : "public", "dataset" :"d1" }, { "_id" : "1123421231234234", "name" : "Total_pop", "description" : "sales category", "source" : "public", "dataset" :"d1" }, { "_id" : "12312342332423343", "name" : "Total_pop", "description" : "sales category", "source" : "private", "description" : "d1" } I need to get collection distinct of dataset where source is public. I tried this query, and it didn't work: Criteria criteria = new Criteria(); criteria.where("source").in("public");

Calculated group-by fields in MongoDB

懵懂的女人 提交于 2019-11-27 02:22:04
问题 For this example from the MongoDB documentation, how do I write the query using MongoTemplate? db.sales.aggregate( [ { $group : { _id : { month: { $month: "$date" }, day: { $dayOfMonth: "$date" }, year: { $year: "$date" } }, totalPrice: { $sum: { $multiply: [ "$price", "$quantity" ] } }, averageQuantity: { $avg: "$quantity" }, count: { $sum: 1 } } } ] ) Or in general, how do I group by a calculated field? 回答1: You can actually do something like this with "project" first, but to me it's a

Geospatial $near within current document field value

北城余情 提交于 2019-11-26 10:03:43
问题 Take this query: { \'location\' : { \'$near\' : [x,y], \'$maxDistance\' : this.field } } I want to assign $maxDistance the value of the specified field from the current evaluated document. Is that possible? 回答1: Yes it's possible. You just use $geoNear instead. Beware the catches and read carefully. Presuming that your intent to is to store a field such as "travelDistance" to indicate on the document that any such searches must be "within" that supplied distance from the queried point to be