forked from Haxe-Nodejs/node-api
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathMongooseTest.hx
57 lines (43 loc) · 1.13 KB
/
MongooseTest.hx
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
package test;
import js.npm.mongoose.macro.Model;
typedef StuffData = {
test : String,
foo : Int,
?bar : {
hello : String,
world : Array<Dynamic>
}
}
// declare the model
// the typedef fields will be "copied" to Stuff instance
@:schemaOptions({
autoIndex: true
})
class Stuff extends Model<StuffData>{}
class StuffManager extends js.npm.mongoose.macro.Manager<StuffData,Stuff>{}
class MongooseTest implements util.Async {
static function main(){
// connect
var db = new js.npm.mongoose.Mongoose();
db.connect("mongodb://localhost/test_mongoose");
// build the model
var stuff = StuffManager.build(db, "Stuff");
// use the model
trace("running test");
var err = @async stuff.remove({});
trace("cleared DB");
var d = {
test : "test",
foo : 1
};
var err,doc = @async stuff.create( d );
trace("CREATE 1", err,doc);
var err,doc = @async stuff.create( { test : "test", foo : 13 } );
trace("CREATE 2", err,doc);
stuff.update( {test:"test"}, {foo:2}, {multi:true}, function(err,response){
js.Node.console.log(js.Kit.arguments);
});
trace("foo", doc.foo);
trace("test",doc.test);
}
}