1

我正在使用 Spring cloud 从文件存储连接和读取数据(在本机模式下使用 Cloud Firestore)。

Pom.xml

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-gcp-starter-data-datastore</artifactId>
</dependency>

Spring GCP 版本 - <gcp.version>1.2.8.RELEASE</gcp.version>

实体

import org.springframework.cloud.gcp.data.datastore.core.mapping.Entity;
import org.springframework.data.annotation.Id;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity(name = "user_profile")
public class UserProfile {

    @Id
    private Long id;

    private String applicationId;

    private String firstName;

}

存储库

import org.springframework.cloud.gcp.data.datastore.repository.DatastoreRepository;

public interface UserProfileRepository extends DatastoreRepository<UserProfile, Long> {
    
    List<UserProfile> findByApplicationId(String applicationId);

}

服务


// Save
 public void register(UserRegistrationRequest dto) {
        
        UserProfile userProfile = new UserProfile();
        userProfile.setFirstName(dto.getFirstName());
    
        userProfile.setApplicationId(tkmIdGenerator.generate(UserType.Candidate));
            
        userProfileRepository.save(userProfile);
    }

// Get
 public void getUserDetails(String applicationId) {
        
        java.util.List<UserProfile> userProfiles = userProfileRepository.findByApplicationId(applicationId, Sort.by(Order.asc("applicationId")));
        System.out.println(userProfiles);
    }

保存工作得很好,但是在尝试读取它时,低于索引不匹配错误。我正在使用单个属性来读取数据。在这种情况下,firestore 会自动创建索引。有点困惑为什么我会收到这个错误。

错误

com.google.datastore.v1.client.DatastoreException: no matching index found.
    at com.google.datastore.v1.client.RemoteRpc.makeException(RemoteRpc.java:136) ~[datastore-v1-proto-client-1.6.3.jar:na]
    at com.google.datastore.v1.client.RemoteRpc.makeException(RemoteRpc.java:185) ~[datastore-v1-proto-client-1.6.3.jar:na]
    at com.google.datastore.v1.client.RemoteRpc.call(RemoteRpc.java:96) ~[datastore-v1-proto-client-1.6.3.jar:na]
    at com.google.datastore.v1.client.Datastore.runQuery(Datastore.java:119) ~[datastore-v1-proto-client-1.6.3.jar:na]
    at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.runQuery(HttpDatastoreRpc.java:198) ~[google-cloud-datastore-1.105.3.jar:1.105.3]
    at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:194) ~[google-cloud-datastore-1.105.3.jar:1.105.3]
    at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:191) ~[google-cloud-datastore-1.105.3.jar:1.105.3]
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105) ~[gax-1.60.1.jar:1.60.1]
4

0 回答 0