Permalink
Browse files

tests for $unset

  • Loading branch information...
1 parent cb16e7c commit c6f5acbcac47c6e1730b59029b924dc536fb2955 @RedBeard0531 RedBeard0531 committed Dec 11, 2009
Showing with 19 additions and 0 deletions.
  1. +19 −0 jstests/unset.js
View
19 jstests/unset.js
@@ -0,0 +1,19 @@
+t = db.unset;
+t.drop();
+
+orig = { _id : 1, emb : {} };
+t.insert(orig);
+
+t.update( { _id : 1 }, { $unset : { 'emb.a' : 1 }});
+t.update( { _id : 1 }, { $unset : { 'z' : 1 }});
+assert.eq( orig , t.findOne() , "A" );
+
+t.update( { _id : 1 }, { $set : { 'emb.a' : 1 }});
+t.update( { _id : 1 }, { $set : { 'z' : 1 }});
+
+t.update( { _id : 1 }, { $unset : { 'emb.a' : 1 }});
+t.update( { _id : 1 }, { $unset : { 'z' : 1 }});
+assert.eq( orig , t.findOne() , "B" ); // note that emb isn't removed
+
+t.update( { _id : 1 }, { $unset : { 'emb' : 1 }});
+assert.eq( {_id :1} , t.findOne() , "C" );

0 comments on commit c6f5acb

Please sign in to comment.