Last active
December 24, 2015 07:29
-
-
Save clemos/6764489 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import js.npm.mongoose.Model; | |
| import js.npm.mongoose.Schema; | |
| import js.npm.Mongoose; | |
| class TestMongoose { | |
| public static function main(){ | |
| Mongoose._.connect( 'mongodb://localhost/test' , cast start ); | |
| } | |
| static function start(err){ | |
| if( err != null ){ | |
| trace(err); | |
| return; | |
| } | |
| var schema = new Schema({ | |
| title : String, | |
| content : String, | |
| date : Date | |
| }); | |
| var model : Models<Dynamic> = Mongoose._.model('Article',schema); | |
| // créer un article | |
| model.create({ title : 'My New Article', content : 'Bla bla'}, function(err, article){ | |
| if( err == null || article == null ){ | |
| throw "Error saving article..."; | |
| } | |
| // mise à jour de l'article | |
| article.date = Date.now(); | |
| article.save(); | |
| }); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated the example with code to connect to a local mongo instance.
Also, regarding Haxe typing (to address your error with
Null<js.npm.mongoose.Model<js.npm.mongoose.Schema>> has no field date)... I just commited a change so
Document(and thusModel) implementsDynamicThis should remove the error, and makes sense until we find a proper way to type Documents / Schemas / Models ...