问题描述
我正在尝试通过 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
日志,它似乎正在发送包含所有字段的插入查询。
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
仍然没有运气。我不知道为什么会这样。请帮忙。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)