Skip to content

DBRef resolution is not supported using only reactive MongoDB [DATAMONGO-2146] #3015

@spring-projects-issues

Description

@spring-projects-issues

eacdy opened DATAMONGO-2146 and commented

I use Spring Boot 2.1.0 with Spring Data Mongo Reactive.

When I call http://localhost:8080/query or http://localhost:8080/query2 

I Can only get an error messge like below:

 

Whitelabel Error PageThis application has no configured error view, so you are seeing this as a fallback.Wed Nov 28 01:35:02 CST 2018There was an unexpected error (type=Internal Server Error, status=500).DBRef resolution is not supported!

 

When I downgrade to Spring Boot 2.0.6, everything turns OK.

 

Code is like below: I've uploaded.[^odin.zip]

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


@Repository
public interface UserRepository extends ReactiveCrudRepository<User, String> {
  Mono<User> findByCompanyId(String companyId);

  Mono<User> findByCompany(Company company);

  @Query("{'company.$id': ?0}")
  Mono<Company> findByCompanyId2(String companyId);
}




@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserController {
  private final UserRepository userRepository;
  private final CompanyRepository companyRepository;

  @GetMapping("/users/{id}")
  public Mono<User> findOne(@PathVariable Integer id) {
    Company company = Company.builder()
      .name("阿里巴巴")
      .build();

    User user = User.builder()
      .username("张三123123")
      .password("密码")
      .company(company)
      .build();

    Mono<Company> companyMono = this.companyRepository.save(company);
    Mono<User> userMono = this.userRepository.save(user);

    return companyMono.then(userMono);
  }

  @GetMapping("query")
  public Mono<User> query() {
    Mono<User> byCompanyId = this.userRepository.findByCompanyId("5bfd7057ce58a2202e9ab105");
    byCompanyId.subscribe(System.out::println);
    return byCompanyId;
  }

  @GetMapping("query2")
  public Mono<User> query2() {
    Mono<User> byCompanyId = this.userRepository.findByCompany(
      Company.builder()
        .id("5bfd7057ce58a2202e9ab105")
        .build()
    );
    byCompanyId.subscribe(System.out::println);
    return byCompanyId;
  }

  @GetMapping("query3")
  public Mono<Company> query3() {
    Mono<Company> byCompanyId = this.userRepository.findByCompanyId2("5bfd7057ce58a2202e9ab105");
    byCompanyId.subscribe(System.out::println);
    return byCompanyId;
  }
}


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document
// 如果不指定,那就是包名全路径
@TypeAlias("company_xx")
public class Company {
  @Id
  private String id;
  private String name;
}


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document
public class User {
  /**
   * ID
   */
  @Id
  private String id;

  /**
   * 用户名
   */
  private String username;

  /**
   * 密码
   */
  private String password;

  @DBRef
  private Company company;
}

 


Affects: 2.1.3 (Lovelace SR3)

Attachments:

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core supportstatus: declinedA suggestion or change that we don't feel we should currently applytype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions