我正在尝试使用拉操作从集合中的数组中删除元素,但是它不起作用 JSON格式
"previousCoverSize" : 0,
"photoList" : [
{
"photoId" : "shrU17266w",
"origUrl" : "vendors/photographer/1503983007582/projects/3585/photos/shrU17266w.jpeg",
"webUrl" : "vendors/photographer/1503983007582/projects/3585/photos/shrU17266w.jpeg",
"mobileUrl" : "vendors/photographer/1503983007582/projects/3585/photos/shrU17266w.jpeg",
"fileType" : "2B6A6418.jpeg",
"dateAdded" : ISODate("2020-02-11T13:10:13.041+05:30"),
"name" : "2B6A6418.jpeg",
"category" : "Birthday shoot",
"vendorId" : "1503983007582",
"vendorType" : "photographer",
"isPrivate" : true,
"selectedByClient" : false,
"setOnHomePage" : false,
"clientFav" : false,
"isWebBanner" : true,
"isMobileBanner" : false,
"isThumbnail" : false,
"isFolder" : false,
"exifData" : {
"Make" : "Canon",
"Model" : "Canon EOS 5D Mark III",
"FocalLength" : "85",
"Flash" : "Flash did not fire, compulsory flash mode",
"DateTimeOriginal" : "2020:02:03 19:34:02",
"GPSLongitude" : "Canon EOS 5D Mark III",
"Size" : "99823",
"Software" : "Adobe Photoshop Lightroom Classic 8.0 (Windows)"
},
"altText" : "Ridhaan Birthday project 2B6A6418.jpeg image.",
"rejected" : false,
"indexNumber" : 2
}
Mongo Shell代码
db.spyne_share.update({"projectId":"3585"},{$pull:{"photoList":{$elemMatch:{photoId:"shrU17266w"}}}})
Java代码
Update update = new Update()
.pull("photoList", new BasicDBObject("photoList.photoId",photoId));
mongoTemplate.updateFirst(new Query(Criteria.where("projectId").is(projectId)), update, "spyne_share");
} catch (Exception e) {
e.printStackTrace();
}
我的这两个代码均无效。请帮帮我。谢谢
问题来源:Stack Overflow
通过将photoList.photoId更改为photoId获得完美的响应
Query query = Query.query(Criteria.where("projectId").is(projectId));
Update update = new Update().pull("photoList", new BasicDBObject("photoId", photoId));
mongoTemplate.updateMulti(query, update, SpyneShareProject.class);
} catch (Exception e) {
e.printStackTrace();
}```
回答来源:Stack Overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。