blob: 10442f7e97a85459b75c28b3786d58b79e1241ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/**
* This tests the basic cases for implicit database creation in a sharded cluster.
*/
(function() {
"use strict";
var st = new ShardingTest({shards: 2});
var configDB = st.s.getDB('config');
assert.eq(null, configDB.databases.findOne());
var testDB = st.s.getDB('test');
// Test that reads will not result into a new config.databases entry.
assert.eq(null, testDB.user.findOne());
assert.eq(null, configDB.databases.findOne({_id: 'test'}));
assert.writeOK(testDB.user.insert({x: 1}));
var testDBDoc = configDB.databases.findOne();
assert.eq('test', testDBDoc._id, tojson(testDBDoc));
// Test that inserting to another collection in the same database will not modify the existing
// config.databases entry.
assert.writeOK(testDB.bar.insert({y: 1}));
assert.eq(testDBDoc, configDB.databases.findOne());
st.s.adminCommand({enableSharding: 'foo'});
var fooDBDoc = configDB.databases.findOne({_id: 'foo'});
assert.neq(null, fooDBDoc);
assert(fooDBDoc.partitioned);
var newShardConn = MongoRunner.runMongod({});
var unshardedDB = newShardConn.getDB('unshardedDB');
unshardedDB.user.insert({z: 1});
assert.commandWorked(st.s.adminCommand({addShard: newShardConn.name}));
assert.neq(null, configDB.databases.findOne({_id: 'unshardedDB'}));
MongoRunner.stopMongod(newShardConn);
st.stop();
})();
|