[JAVA-324] findAndModify is applied on $cmd collection and hence does not use the ObjectClass of the target collection Created: 13/Apr/11  Updated: 18/Jun/12  Resolved: 17/May/12

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.8.0

Type: Bug Priority: Major - P3
Reporter: Antoine Girbal Assignee: Jeffrey Yemin
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to JAVA-569 findAndModify should use internal cla... Closed

 Description   

Need to use a sort of setinternalclass to apply to the value subobject.
But since $cmd collection is unique and applied to any collection, the internalclass needs to be decided on the fly, not static.
Will be a bit of a hack to fix.



 Comments   
Comment by Jeffrey Yemin [ 18/Jun/12 ]

Closing for 2.8.0 release.

Comment by auto [ 17/May/12 ]

Author:

{u'login': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-324: Supporing object class (but not internal classes) for findAndModify
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/be9840c71d4ae54aaa31cc567ecfde90d21dac69

Comment by Jeffrey Yemin [ 10/May/12 ]

I have a fix that uses the object class set on the collection but not any internal classes. Will that allow you to move forward? In other words, this test will pass:

 
    static class Process extends ReflectionDBObject {
 
        public Process() {}
 
        public String getName() {
            return name;
        }
 
        public void setName(String name) {
            this.name = name;
        }
 
        public int getStatus() {
            return status;
        }
 
        public void setStatus(int status) {
            this.status = status;
        }
 
        String name;
        int status;
    }
 
    @Test
    public void testFindAndModify() {
        DBCollection c = _db.getCollection( "findAndModify" );
        c.drop();
        c.setObjectClass( Process.class );
 
        Process p = new Process();
        p.setName("test");
        p.setStatus(0);
        c.save(p, WriteConcern.SAFE);
 
        DBObject obj = c.findAndModify(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("status", 1)));
        assertEquals(Process.class, obj.getClass());
        Process pModified = (Process) obj;
        assertEquals(0, pModified.getStatus());
        assertEquals("test", pModified.getName());
 
    }

Comment by Wendal Chen [ 01/Feb/12 ]

Any plan for that??

Comment by Leif Mortenson [ 23/Apr/11 ]

We are having a problem with this as well and look forward to a fix.

It would be great if collection.setObjectClass worked with objects returned by collection.findAndModify.

Cheers,
Leif

Generated at Thu Feb 08 08:52:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.