File: repl9.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (48 lines) | stat: -rw-r--r-- 1,633 bytes parent folder | download | duplicates (5)
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
// Test replication of collection renaming

baseName = "jstests_repl_repl9";

rt = new ReplTest( "repl9tests" );

m = rt.start( true );
s = rt.start( false );

admin = m.getDB( "admin" );

debug = function( foo ) {} // print( foo ); }

// rename within db

m.getDB( baseName ).one.save( { a: 1 } );
assert.soon( function() { v = s.getDB( baseName ).one.findOne(); return v && 1 == v.a } );

assert.commandWorked( admin.runCommand( {renameCollection:"jstests_repl_repl9.one", to:"jstests_repl_repl9.two"} ) );
assert.soon( function() {
	if ( -1 == s.getDB( baseName ).getCollectionNames().indexOf( "two" ) ) {
	    debug( "no two coll" );
	    debug( tojson( s.getDB( baseName ).getCollectionNames() ) );
	    return false;
	}
	if ( !s.getDB( baseName ).two.findOne() ) {
	    debug( "no two object" );
	    return false;
	}
	    return 1 == s.getDB( baseName ).two.findOne().a; });
assert.eq( -1, s.getDB( baseName ).getCollectionNames().indexOf( "one" ) );

// rename to new db

first = baseName + "_first";
second = baseName + "_second";

m.getDB( first ).one.save( { a: 1 } );
assert.soon( function() { return s.getDB( first ).one.findOne() && 1 == s.getDB( first ).one.findOne().a; } );

assert.commandWorked( admin.runCommand( {renameCollection:"jstests_repl_repl9_first.one", to:"jstests_repl_repl9_second.two"} ) );
assert.soon( function() {
	return -1 != s.getDBNames().indexOf( second ) &&
	    -1 != s.getDB( second ).getCollectionNames().indexOf( "two" ) &&
	    s.getDB( second ).two.findOne() &&
	    1 == s.getDB( second ).two.findOne().a; } );
assert.eq( -1, s.getDB( first ).getCollectionNames().indexOf( "one" ) );