summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2013-11-14 09:13:38 -0500
committerScott Hernandez <scotthernandez@gmail.com>2013-11-14 09:26:00 -0500
commit103da34ddbc32d8345655471fc46afc6352a6624 (patch)
treef974ac9cae473b85442dc9d4bc7415e4d0650acc
parent9a28a092d50eeb1bd45815b256f0180044a5c588 (diff)
downloadmongo-103da34ddbc32d8345655471fc46afc6352a6624.tar.gz
SERVER-11700: more diagnostics
-rw-r--r--jstests/basic3.js61
-rw-r--r--jstests/basic9.js34
2 files changed, 42 insertions, 53 deletions
diff --git a/jstests/basic3.js b/jstests/basic3.js
index 44888654240..d778974f64a 100644
--- a/jstests/basic3.js
+++ b/jstests/basic3.js
@@ -1,50 +1,45 @@
-
+// Tests that "." cannot be in field names
t = db.getCollection( "foo_basic3" );
-
-t.find( { "a.b" : 1 } ).toArray();
-
-ok = true;
-
-try{
- t.save( { "a.b" : 5 } );
- ok = false;
-}
-catch ( e ){
+t.drop()
+
+//more diagnostics on bad save, if exception fails
+doBadSave = function(param) {
+ print("doing save with " + tojson(param))
+ t.save(param);
+ // Should not get here.
+ printjson(db.getLastErrorObj());
}
-assert( ok , ". in names aren't allowed doesn't work" );
-try{
- t.save( { "x" : { "a.b" : 5 } } );
- ok = false;
+//more diagnostics on bad save, if exception fails
+doBadUpdate = function(query, update) {
+ print("doing update with " + tojson(query) + " " + tojson(update))
+ t.update(query, update);
+ // Should not get here.
+ printjson(db.getLastErrorObj());
}
-catch ( e ){
-}
-assert( ok , ". in embedded names aren't allowed doesn't work" );
+
+assert.throws(doBadSave, [{"a.b":5}], ". in names aren't allowed doesn't work");
+
+assert.throws(doBadSave,
+ [{ "x" : { "a.b" : 5 } }],
+ ". in embedded names aren't allowed doesn't work");
// following tests make sure update keys are checked
t.save({"a": 0,"b": 1})
-try {
- t.update({"a": 0}, {"b.b": 1});
- ok = false;
-} catch (e) {}
-assert( ok , "must deny '.' in key of update" );
+
+assert.throws(doBadUpdate, [{a:0}, { "b.b" : 1 }],
+ "must deny '.' in key of update");
// upsert with embedded doc
-try {
- t.update({"a": 10}, {"b": { "c.c" : 1 }}, true);
- ok = false;
-} catch (e) {}
-assert( ok , "must deny '.' in key of update" );
+assert.throws(doBadUpdate, [{a:10}, { c: {"b.b" : 1 }}],
+ "must deny embedded '.' in key of update");
// if it is a modifier, it should still go through
t.update({"a": 0}, {$set: { "c.c": 1}})
t.update({"a": 0}, {$inc: { "c.c": 1}})
// edge cases
-try {
- t.update({"a": 0}, {"": { "c.c": 1}})
- ok = false;
-} catch (e) {}
-assert( ok , "must deny '.' in key of update" );
+assert.throws(doBadUpdate, [{a:0}, { "":{"b.b" : 1} }],
+ "must deny '' embedded '.' in key of update");
t.update({"a": 0}, {})
diff --git a/jstests/basic9.js b/jstests/basic9.js
index 3395a41ed7b..b8308fba7d0 100644
--- a/jstests/basic9.js
+++ b/jstests/basic9.js
@@ -1,25 +1,19 @@
-
+// Tests that $<prefix> field names are not allowed, but you can use a $ anywhere else.
t = db.getCollection( "foo_basic9" );
+t.drop()
-t.save( { "foo$bar" : 5 } );
-
-ok = false;
-
-try{
- t.save( { "$foo" : 5 } );
- ok = false;
+// more diagnostics on bad save, if exception fails
+doBadSave = function(param) {
+ print("doing save with " + tojson(param))
+ t.save(param);
+ // Should not get here.
+ printjson(db.getLastErrorObj());
}
-catch ( e ){
- ok = true;
-}
-assert( ok , "key names aren't allowed to start with $ doesn't work" );
-try{
- t.save( { "x" : { "$foo" : 5 } } );
- ok = false;
-}
-catch ( e ){
- ok = true;
-}
-assert( ok , "embedded key names aren't allowed to start with $ doesn't work" );
+t.save({foo$foo:5});
+t.save({foo$:5});
+assert.throws(doBadSave, [{$foo:5}], "key names aren't allowed to start with $ doesn't work");
+assert.throws(doBadSave,
+ [{x:{$foo:5}}],
+ "embedded key names aren't allowed to start with $ doesn't work");