MongoTemplate 拉取查询在 mongo shell 和 spring mongo 模板中不起作用

MongoTemplate Pull query not working in mongo shell and spring mongoTemplate

我正在尝试使用拉取操作从集合中的数组中删除一个元素,但它不起作用

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
        }

Mongoshell代码

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();
        }

我的这两个代码都不起作用。请帮帮我。谢谢

通过将 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();
        }```