File: noUpdateButN1inAnotherCollection.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 (60 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download | duplicates (3)
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
57
58
59
60

function debug( str ) {
    print( "---\n" + str + "\n-----" );
}

var name = "badNonUpdate";
debug("Starting sharded cluster test stuff");

s = new ShardingTest( {name: name, shards : 2, mongos : 2, separateConfig : true, verbose:5, nopreallocj : true });

var mongosA=s.s0;
var mongosB=s.s1;

ns = "test.coll";
ns2 = "test.coll2";

adminSA = mongosA.getDB( "admin" );
adminSA.runCommand({ enableSharding : "test"});

adminSA.runCommand( { moveprimary : "test", to : "shard0000" } );
adminSA.runCommand( { moveprimary : "test2", to : "shard0001" } );

adminSA.runCommand({ shardCollection : ns, key : { _id : 1 } });

try {
   s.stopBalancer();
} catch (e) { 
   print("coundn't stop balancer via command"); 
}

adminSA.settings.update({ _id: 'balancer' }, { $set: { stopped: true }});

var db = mongosA.getDB( "test" );
var coll = db.coll;
var coll2 = db.coll2;

numDocs = 10;
for (var i = 1; i < numDocs; i++) {
    coll.insert({_id:i, control:0});
    coll2.insert({_id:i, control:0});
}

debug("Inserted docs, now split chunks");

adminSA.runCommand( { split: ns, find : { _id : 3} });
adminSA.runCommand( { movechunk: ns, find : { _id : 10}, to: "shard0001" });

var command = 'db.coll.update({_id:9},{$set:{"a":"9"}},true);printjson(db.getLastErrorObj())';

// without this first query through mongo, the second time doesn't "fail"
debug("Try query first time");
var GLE2=runMongoProgram( "mongo", "--quiet", "--port", "" + s._mongos[1].port, "--eval", command );

mongosB.getDB("test").coll2.update({_id:0}, {$set:{"c":"333"}});
var GLE3=mongosB.getDB("test").getLastErrorObj();
assert.eq( 0, GLE3.n );


s.stop();