forked from timburks/NuMongoDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.nu
62 lines (44 loc) · 1.67 KB
/
run.nu
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
61
(load "NuMongoDB")
(set collection "test.sample")
(set mongo (NuMongoDB new))
(puts "connecting")
(mongo connectWithOptions:(dict host:"127.0.0.1"))
(puts "connected")
(mongo dropCollection:"sample" inDatabase:"test")
(puts "ok")
(set sample (dict one:1
two:2.0
three:"3"
four:(array "zero" "one" "two" "three")
leaf:(NSData dataWithContentsOfFile:"mongoleaf.png")))
(mongo insertObject:sample intoCollection:collection)
(puts "ok")
(10 times:
(do (i)
(10 times:
(do (j)
(set object (dict i:i j:j name:(+ "mongo-" i "-" j) (+ "key-" i "-" j) sample))
(set bson ((NuBSON alloc) initWithDictionary:object))
(mongo insert:bson intoCollection:collection)))))
(set cursor (mongo find:(dict $where:"this.i == 3") inCollection:collection))
(while (cursor next)
(set bson (cursor currentBSON))
(set object (bson dictionaryValue))
(puts (object description)))
(puts "updating")
(mongo update:((NuBSON alloc) initWithDictionary:(dict "$set" (dict k:456)))
inCollection:collection
withCondition:((NuBSON alloc) initWithDictionary:(dict i:3))
insertIfNecessary:YES
updateMultipleEntries:YES)
(set cursor (mongo find:(dict i:3) inCollection:collection))
(while (cursor next)
(puts "iterating")
(set bson (cursor currentBSON))
(set object (bson dictionaryValue))
(puts (object description)))
(puts "ok")
(set first (mongo findOne:(dict one:1) inCollection:collection))
(puts (first description))
(set leaf (first leaf:))
(puts (eq leaf (NSData dataWithContentsOfFile:"mongoleaf.png")))