SpringMongoDB有些字段根本没有保存或更新

5tmbdcev  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(292)

我正试图在中保存一个文档 MongoDB 通过收集 MongoRepository.save 方法。这是我的密码。
文档类:

@Document(collection = "appointments")
   public class AppointmentDocument extends AbstractCommonDocument {
       @Id
       private ObjectId _id;
       @DBRef(lazy = true)
       private ServiceDocument service;
       @DBRef(lazy = true)
       private FeedbackDocument feedback;
       private String status;
       private String appointmentType;
       private String description;
       private EmbeddedPeriod period;
       private EmbeddedPeriod requestedPeriod;
       @Deprecated
       private ProviderFeedback providerFeedback;
       private List<Participant> participants;
       private List<AppointmentResponse> appointmentResponses;
       @Deprecated
       private AppointmentPayment paymentDetails;
       private CommunityPayment prePayment;
       private CommunityPayment postPayment;
       private boolean requestedByPatient;
       @Deprecated
       private DateTime acceptedAt;
       private DateTime requestedAt;
       private DateTime confirmedAt;
       private DateTime cancelledAt;
       private DateTime completedAt;
       private String requestMessage;
       private String mondayId;

       ...getters & setters
   }

存储库:

@Repository
public interface AppointmentRepository extends MongoRepository<AppointmentDocument, String> {

}

保存记录的代码。

AppointmentDocument appointmentDocument = new AppointmentDocument();

    // ...omitted set calls for other fields for brevity
    appointmentDocument.setRequestedByPatient(!isProvider);
    appointmentDocument.setRequestedAt(requestedAt);
    appointmentDocument.setRequestMessage(request.getComment());
    appointmentDocument = appointmentRepository.save(appointmentDocument);

问题是所有字段都保存在数据库中,除了 requestedAt 以及 requestMessage 现场。没有错误日志,我已启用 MongoDB 它似乎正在发送包含所有字段的insert查询。

DEBUG o.s.data.mongodb.core.MongoTemplate - 2021-04-21 19:22:58 - Inserting Document containing fields: [service, status, period, requestedPeriod, participants, appointmentResponses, prePayment, requestedByPatient, requestedAt, requestMessage, createdAt, lastModified, _class] in collection: appointments

我还是看到了 requestedAt 以及 requestMessage 数据库中的文档中缺少。
我还尝试在通过保存文档后更新记录 mongoTemplate.updateFirst 方法。还是不走运。这是密码。

mongoTemplate.updateFirst(
                new Query(where("_id").is(appointmentDocument.get_id())),
                new Update()
                        .set("requestedAt",requestedAt)
                        .set("requestMessage", request.getComment()),
                AppointmentDocument.class
        );

我再次看到更新日志。。

DEBUG o.s.data.mongodb.core.MongoTemplate - 2021-04-21 19:22:58 - Calling update using query: { "_id" : { "$oid" : "60807b92adbe1d0001c2bed6" } } and update: { "$set" : { "requestedAt" : { "$date" : 1619032978091 }, "requestMessage" : "Dummy Request message" } } in collection: appointments

还是不走运。我不知道为什么会这样。请帮忙。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题