/
update.t
51 lines (38 loc) · 1.31 KB
/
update.t
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
use v6;
use Test;
use MongoDB::Connection;
my $connection = MongoDB::Connection.new;
my $database = $connection.database( 'test' );
my $collection = $database.collection( 'perl6_driver' );
# TODO replace with drop when available
$collection.remove( );
# feed test data
$collection.insert( { 'foo' => 0 }, { 'foo' => 0 } );
lives-ok {
$collection.update( { 'foo' => 0 }, { '$inc' => { 'foo' => 1 } } );
}, 'update single document';
lives-ok {
$collection.update( { 'foo' => { '$exists' => True } }, { '$inc' => { 'foo' => 1 } }, :multi_update );
}, 'update many documents with multi_update flag';
lives-ok {
$collection.update( { 'bar' => 0 }, { '$inc' => { 'bar' => 1 } } );
}, 'update nonexisting document';
lives-ok {
$collection.update( { 'bar' => 0 }, { '$inc' => { 'bar' => 1 } }, :upsert );
}, 'update nonexisting document with upsert flag';
dies-ok {
$collection.update( );
}, 'update without selector and document is forbidden';
dies-ok {
$collection.update( 1, "a" );
}, 'update fails on incorrect document types';
# TODO check output, expected result
# { "_id" : ObjectId("..."), "foo" : 2 }
# { "_id" : ObjectId("..."), "foo" : 1 }
# { "_id" : ObjectId("..."), "bar" : 1 }
#-----------------------------------------------------------------------------
# Cleanup
#
$database.drop;
done();
exit(0);