spring-mongodb

MongoDb: how to search in multiple collections?

陌路散爱 提交于 2021-01-29 06:06:24
问题 I got this structure in my mongodb (2 collections: restaurant and cocktail ) restaurant {id=1001, name="Res1", coor=[12.392, 19.123], cocktail=[13, 0, 92]} cocktail {id=13, name="Capiroska"}, {id=167, name="Capirinha"}, {id=92, name="Negroni"}, {id=0, name="Martini"} Multiple restaurant s and multiple cocktail s, N:N relationship. My goal is to find which different cocktail s I can drink within a specified area. I've already written a query that finds all restaurants near my position like

Mongo aggregation vs Java for loop and performance

ε祈祈猫儿з 提交于 2021-01-03 06:53:21
问题 I have a below mongo document stored { "Field1": "ABC", "Field2": [ { "Field3": "ABC1","Field4": [ {"id": "123" }, { "id" : "234" }, { "id":"345" }] }, { "Field3": "ABC2","Field4": [ {"id": "123" }, { "id" : "234" }, { "id":"345" }] }, { "Field3": "ABC3","Field4": [{ "id":"345" }] }, ] } from the above, I want to fetch the subdocuments which is having id "123" ie. { "Field3" : "ABC1", "Field4" : [ { "id": "123"} ] } , { "Field3" : "ABC2", "Field4" : [ { "id": "123"} ] } 1. Java way A. use

How to update particular field in mongo db by using MongoRepository Interface?

試著忘記壹切 提交于 2020-05-23 23:53:55
问题 How to update a particular field in mongo db collection by using MongoRepository Interface in spring? 回答1: I am sure you got the answer by far now, still updating it to help other folks. you can update specific field by below code., Query query1 = new Query(Criteria.where("id").is("123")); Update update1 = new Update(); update1.set("available", false); mongoTemplate.updateFirst(query1, update1, Customer.class); 来源: https://stackoverflow.com/questions/38973231/how-to-update-particular-field-in

Spring MongoDB Data elemMatch Simple

萝らか妹 提交于 2020-04-11 06:15:10
问题 { _id: 1, results: [ "tokyo", "japan" ] } { _id: 2, results: [ "sydney", "australia" ] } db.scores.find( { results: { $elemMatch: { $regex: *some regex* } } } ) How do you convert this simple elemMatch example using spring mongodb data Query Criteria? If the array contains object I can do it this way Criteria criteria = Criteria.where("results"). elemMatch( Criteria.where("field").is("tokyo") ); But in my question, I dont have the "field" Update: I thought the Veeram's answer was going to

Spring Mongo DB @DBREF

筅森魡賤 提交于 2020-02-29 12:50:16
问题 This is my MongoDb structure, db.user.find(); user: { "name" : "KSK", "claim" : [objectId("52ffc4a5d85242602e000000"),objectId("52ffc4a5d85242602e000001")] } claim: [ { "_id" : "52ffc4a5d85242602e000001", "claimName" :"XXXX" }, { "_id" : "52ffc4a5d85242602e000000", "claimName" :"YYY" } ] My Entity class is: @Document(collection="user") public class User{ @Id private String id; private String name; @DBRef private List<Claim> claim; // setter and getter } Claim Class: @Document(collection=

Spring Mongo DB @DBREF

本小妞迷上赌 提交于 2020-02-29 12:50:08
问题 This is my MongoDb structure, db.user.find(); user: { "name" : "KSK", "claim" : [objectId("52ffc4a5d85242602e000000"),objectId("52ffc4a5d85242602e000001")] } claim: [ { "_id" : "52ffc4a5d85242602e000001", "claimName" :"XXXX" }, { "_id" : "52ffc4a5d85242602e000000", "claimName" :"YYY" } ] My Entity class is: @Document(collection="user") public class User{ @Id private String id; private String name; @DBRef private List<Claim> claim; // setter and getter } Claim Class: @Document(collection=

How to import JSON data files to mongodb with Spring Boot?

放肆的年华 提交于 2020-01-14 16:45:47
问题 As you know, when using spring boot jpa module, below codes in application.properties import pre-defined sql data to rdb. spring.datasource.initialization-mode = always spring.datasource.data = classpath:/sql/spring-boot-mysql.sql But when using mongodb as storage, what properties codes in application.properties file can import pre-defined JSON data of external files? If such properties do not exit, how can the JSON data be imported from the external files with spring boot? 回答1: I don't know

mongodb mongoTemplate get distinct field with some criteria

浪子不回头ぞ 提交于 2020-01-11 00:06:44
问题 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

Spring mongo aggregation filter with $and, $in and $eq conditions

和自甴很熟 提交于 2020-01-10 06:11:06
问题 { "Field1": "ABC", "Field2": [ { "Field3": "ABC1","Field4": "REVIEWED","Field5":"True" }, { "Field3": "ABC2","Field4": "APPROVED","Field5":"True" }, { "Field3": "ABC3","Field4": "REJECTED","Field5":"True" }, { "Field3": "ABC4","Field4": "APPROVED","Field5":"False" } ] } I want to fetch APPROVED,REVIEWED and True record ie. { "Field1": "ABC", "Field2": [ { "Field3": "ABC1","Field4": "REVIEWED","Field5":"True" }, { "Field3": "ABC2","Field4": "APPROVED","Field5":"True" } ] } following mongo