spring-data-mongodb

How to log the queries executed by Spring Data MongoDB?

允我心安 提交于 2021-02-04 05:41:17
问题 Is there a way to find the query that was run against the database in spring data mongodb? I know this is possible in case of JPA. So was just wondering if there was something similar in Spring data MongoDB? 回答1: The easiest way is to set the log level to DEBUG for org.springframework.data.mongodb . 回答2: logging: level: org.springframework.data.mongodb.core.MongoTemplate: DEBUG To clarify Oliver's answer add that to the application.yml file or properties file. 来源: https://stackoverflow.com

MongoDB $addFields using org.springframework.data.mongodb.core.MongoTemplate

只谈情不闲聊 提交于 2021-01-29 22:50:09
问题 How do I go about writing an $addFields query in Spring Data MongoDB Reactive for a simpler and a slightly more complex field addition as shown below: db.getCollection("mycollection").aggregate( [ { "$addFields" : { "existingObjectField.newFieldArray" : [ "$existingObjectField.existingFieldObject" ] } }, { "$addFields" : { "existingFieldArray" : { "$map" : { "input" : "$existingFieldArray", "as" : "item", "in" : { "existingFieldObject" : { "_id" : "$$item. existingFieldObject._id",

MongoDB $addFields using org.springframework.data.mongodb.core.MongoTemplate

拥有回忆 提交于 2021-01-29 22:44:34
问题 How do I go about writing an $addFields query in Spring Data MongoDB Reactive for a simpler and a slightly more complex field addition as shown below: db.getCollection("mycollection").aggregate( [ { "$addFields" : { "existingObjectField.newFieldArray" : [ "$existingObjectField.existingFieldObject" ] } }, { "$addFields" : { "existingFieldArray" : { "$map" : { "input" : "$existingFieldArray", "as" : "item", "in" : { "existingFieldObject" : { "_id" : "$$item. existingFieldObject._id",

MongoDB $addFields using org.springframework.data.mongodb.core.MongoTemplate

。_饼干妹妹 提交于 2021-01-29 22:30:38
问题 How do I go about writing an $addFields query in Spring Data MongoDB Reactive for a simpler and a slightly more complex field addition as shown below: db.getCollection("mycollection").aggregate( [ { "$addFields" : { "existingObjectField.newFieldArray" : [ "$existingObjectField.existingFieldObject" ] } }, { "$addFields" : { "existingFieldArray" : { "$map" : { "input" : "$existingFieldArray", "as" : "item", "in" : { "existingFieldObject" : { "_id" : "$$item. existingFieldObject._id",

MongoDB $addFields using org.springframework.data.mongodb.core.MongoTemplate

北城以北 提交于 2021-01-29 21:40:40
问题 How do I go about writing an $addFields query in Spring Data MongoDB Reactive for a simpler and a slightly more complex field addition as shown below: db.getCollection("mycollection").aggregate( [ { "$addFields" : { "existingObjectField.newFieldArray" : [ "$existingObjectField.existingFieldObject" ] } }, { "$addFields" : { "existingFieldArray" : { "$map" : { "input" : "$existingFieldArray", "as" : "item", "in" : { "existingFieldObject" : { "_id" : "$$item. existingFieldObject._id",

Spring Boot handle multiple MongoTemplates for Multi Cluster MongoDB

心已入冬 提交于 2021-01-29 17:44:11
问题 I have to implement multi-tenancy using spring-boot, mongodb. Previously I was using same cluster so things were simple enough. Now each tenant would have its own database in its own cluster. So I was thinking of having multiple mongoTemplates managed in a single application. My requirements: I wanted all Spring configuration in Java code/annotations. (I hate XML!) I wanted Spring to manage both the Mongo and MongoTemplate objects. I wanted to use MongoRepository Interface beans and have the

I want result with distinct value of one field from mongodb using spring data

耗尽温柔 提交于 2021-01-27 09:34:27
问题 I want result with distinct value of one field from mongodb using spring data. My code is Query query = new Query(); query.addCriteria(Criteria.where("to.toId").in(toIdList)); query.fields().include("from"); query.fields().include("fromName"); query.fields().include("sentTime"); query.fields().include("hasAttachment"); newMessages = mongoTemplate.find(query, NewMessage.class); 回答1: You can use distinct instead of find: db.mycollection.distinct('fieldname', query) Using SpringData the syntax

How to use db references with reactive Spring Data MongoDB?

本小妞迷上赌 提交于 2021-01-21 08:32:06
问题 I'm new to MongoDB and Reactor and I'm trying to retrieve a User with its Profiles associated Here's the POJO : public class User { private @Id String id; private String login; private String hashPassword; @Field("profiles") private List<String> profileObjectIds; @Transient private List<Profile> profiles; } public class Profile { private @Id String id; private @Indexed(unique = true) String name; private List<String> roles; } The problem is, how do I inject the profiles in the User POJO ? I'm

Spring MongoDB query documents if days difference is x days

元气小坏坏 提交于 2021-01-21 06:35:49
问题 I have a collection that has two date fields and I am trying to query all records that have a difference of 15 days: { "_id" : "someid", "factoryNumber" : 123, "factoryName" : "some factory name", "visitType" : "audit", "personelId" : "somePersonel", "lastVisit": ISODate("2018-10-30T00:00:00.000+0000"), "acceptedDate" : ISODate("2018-11-16T00:00:00.000+0000") } Now in some cases acceptedDate will not be there so i need to evaluate it against the current date. Not complete sure how to write

Cannot create namespace in multi-document transaction(MongoDB 4.0, Spring Data 2.1.0, Spring Boot)

ⅰ亾dé卋堺 提交于 2021-01-20 07:20:52
问题 This question regarding to Spring boot, Mongo4.0, Spring-data application. I have upgraded from MongoDB 3.6.x to MongoDB 4.0 and Spring data 2.0.x to Spring-data 2.1.0 for transactional management while inserting data into multiple documents. But here I face this issue while creating a database, collection and inserting a document into the collection. Issue Cannot create namespace sampledb_200.demo in multi-document transaction Here sampldb_200 is database name and demo is the collection name