Skip to content

Instantly share code, notes, and snippets.

@clemos
Last active December 24, 2015 07:29
Show Gist options
  • Select an option

  • Save clemos/6764489 to your computer and use it in GitHub Desktop.

Select an option

Save clemos/6764489 to your computer and use it in GitHub Desktop.
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();
});
}
}
@clemos

clemos commented Oct 2, 2013

Copy link
Copy Markdown
Author

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 thus Model) implements Dynamic
This should remove the error, and makes sense until we find a proper way to type Documents / Schemas / Models ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment