2013-11-14 09:13:38 -05:00
|
|
|
// Tests that "." cannot be in field names
|
2016-03-09 12:17:50 -05:00
|
|
|
t = db.getCollection("foo_basic3");
|
2016-02-04 12:29:01 -05:00
|
|
|
t.drop();
|
2013-11-14 09:13:38 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
// more diagnostics on bad save, if exception fails
|
2013-11-14 09:13:38 -05:00
|
|
|
doBadSave = function(param) {
|
2016-02-04 12:29:01 -05:00
|
|
|
print("doing save with " + tojson(param));
|
2014-01-14 14:09:42 -05:00
|
|
|
var res = t.save(param);
|
2013-11-14 09:13:38 -05:00
|
|
|
// Should not get here.
|
2014-01-14 14:09:42 -05:00
|
|
|
printjson(res);
|
2016-02-04 12:29:01 -05:00
|
|
|
};
|
2009-01-26 23:28:26 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
// more diagnostics on bad save, if exception fails
|
2013-11-14 09:13:38 -05:00
|
|
|
doBadUpdate = function(query, update) {
|
2016-02-04 12:29:01 -05:00
|
|
|
print("doing update with " + tojson(query) + " " + tojson(update));
|
2014-01-14 14:09:42 -05:00
|
|
|
var res = t.update(query, update);
|
2013-11-14 09:13:38 -05:00
|
|
|
// Should not get here.
|
2014-01-14 14:09:42 -05:00
|
|
|
printjson(res);
|
2016-02-04 12:29:01 -05:00
|
|
|
};
|
2013-11-14 09:13:38 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.throws(doBadSave, [{"a.b": 5}], ". in names aren't allowed doesn't work");
|
2013-11-14 09:13:38 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.throws(doBadSave, [{"x": {"a.b": 5}}], ". in embedded names aren't allowed doesn't work");
|
2010-12-17 10:54:26 -08:00
|
|
|
|
|
|
|
|
// following tests make sure update keys are checked
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({"a": 0, "b": 1});
|
2013-11-14 09:13:38 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.throws(doBadUpdate, [{a: 0}, {"b.b": 1}], "must deny '.' in key of update");
|
2010-12-17 10:54:26 -08:00
|
|
|
|
|
|
|
|
// upsert with embedded doc
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.throws(doBadUpdate, [{a: 10}, {c: {"b.b": 1}}], "must deny embedded '.' in key of update");
|
2010-12-17 10:54:26 -08:00
|
|
|
|
|
|
|
|
// if it is a modifier, it should still go through
|
2016-03-09 12:17:50 -05:00
|
|
|
t.update({"a": 0}, {$set: {"c.c": 1}});
|
|
|
|
|
t.update({"a": 0}, {$inc: {"c.c": 1}});
|
2010-12-17 10:54:26 -08:00
|
|
|
|
|
|
|
|
// edge cases
|
2016-05-28 17:55:12 -04:00
|
|
|
assert.throws(
|
|
|
|
|
doBadUpdate, [{a: 0}, {"": {"b.b": 1}}], "must deny '' embedded '.' in key of update");
|
2016-02-04 12:29:01 -05:00
|
|
|
t.update({"a": 0}, {});
|