blob: 33899957755d1aaa9626101edf3c1fe055bae8bb (
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
47
48
49
50
51
52
53
54
55
56
|
// ***************************************************************
// rename7.js
// Test renameCollection functionality across different databases.
// ***************************************************************
// Set up namespaces a and b.
admin = db.getMongo().getDB( "admin" );
db_a = db.getMongo().getDB( "db_a" );
db_b = db.getMongo().getDB( "db_b" );
a = db_a.rename7;
b = db_b.rename7;
a.drop();
b.drop();
// Put some documents and indexes in a.
a.save( {a: 1} );
a.save( {a: 2} );
a.save( {a: 3} );
a.ensureIndex( {a: 1} );
a.ensureIndex( {b: 1} );
assert.commandWorked( admin.runCommand( {renameCollection: "db_a.rename7", to: "db_b.rename7"} ) );
assert.eq( 0, a.find().count() );
assert( !db_a.system.namespaces.findOne( {name: "db_a.rename7"} ) );
assert.eq( 3, b.find().count() );
assert( db_b.system.namespaces.findOne( {name: "db_b.rename7"} ) );
assert( b.find( {a: 1} ).explain().cursor.match( /^BtreeCursor/ ) );
a.drop();
b.drop();
// Capped collection testing.
db_a.createCollection( "rename7_capped", {capped:true, size:10000} );
a = db_a.rename7_capped;
b = db_b.rename7_capped;
a.save( {a: 1} );
a.save( {a: 2} );
a.save( {a: 3} );
assert.commandWorked( admin.runCommand( {renameCollection: "db_a.rename7_capped",
to: "db_b.rename7_capped"} ) );
assert.eq( 0, a.find().count() );
assert( !db_a.system.namespaces.findOne( {name: "db_a.rename7_capped"} ) );
assert.eq( 3, b.find().count() );
assert( db_b.system.namespaces.findOne( {name: "db_b.rename7_capped"} ) );
assert.eq( true, db_b.system.namespaces.findOne( {name:"db_b.rename7_capped"} ).options.capped );
assert.eq( 12288, b.stats().storageSize );
a.drop();
b.drop();
|