So, i am making this program, trying to learn more about Spring and MongoDb. I have built this ticked module, that uses a MongoDb to store ticket info in a JSON format. It looks something like this:
所以,我正在制作这个程序,试图了解有关Spring和MongoDb的更多信息。我已经构建了这个勾选的模块,它使用MongoDb以JSON格式存储票证信息。它看起来像这样:
> {
> "_id" : ObjectId("581fb1a24beb291d27f95a50"),
> "userID" : "581ddccb4beb29112a7b4f77",
> "ticketStatus" : "Processing",
> "ticketSolution" : "Not_Solved",
> "ticketComment" : null;
> }
My question is how do i insert a comment into the "ticketComment" field? (I would need something that uses Criteria.where("ticketID").is(ticketID))
我的问题是如何在“ticketComment”字段中插入注释? (我需要使用Criteria.where(“ticketID”)的东西。是(ticketID))
2 个解决方案
#1
1
With simplest details use :-
使用最简单的细节: -
Criteria.where("ticketID").is(ticketID));
Query query = new Query(criteria);
BasicDBObject newValues = new BasicDBObject(columnName,value);
BasicDBObject set = new BasicDBObject("$set", newValues);
Update update = new BasicUpdate(set);
mongoOperations.updateMulti(query, update, "collectionName")
#2
0
So, after some messing around, i have found another approach to this problem.
所以,经过一些麻烦,我找到了解决这个问题的另一种方法。
@Override
public void addTicketComment(String ticketID, String ticketComment) {
Ticket ticket = mongoTemplate.findById(ticketID, Ticket.class);
ticket.getTicketComments().add(ticketComment);
mongoTemplate.save(ticket);
}
#1
1
With simplest details use :-
使用最简单的细节: -
Criteria.where("ticketID").is(ticketID));
Query query = new Query(criteria);
BasicDBObject newValues = new BasicDBObject(columnName,value);
BasicDBObject set = new BasicDBObject("$set", newValues);
Update update = new BasicUpdate(set);
mongoOperations.updateMulti(query, update, "collectionName")
#2
0
So, after some messing around, i have found another approach to this problem.
所以,经过一些麻烦,我找到了解决这个问题的另一种方法。
@Override
public void addTicketComment(String ticketID, String ticketComment) {
Ticket ticket = mongoTemplate.findById(ticketID, Ticket.class);
ticket.getTicketComments().add(ticketComment);
mongoTemplate.save(ticket);
}