Compile your first model
var xxschema = new Schema ({name: ' string ', Size: ' String '}), var Tank = Mongoose.model (' Tank ', Schema);
Construct document
Document is an example of model. Creating updated document to data is easy
var Tank = Mongoose.model (' Tank ', Tankschema), var small = new Tank ({size: ' small '}), Small.save (function (err) { if ( ERR) return Handlererror (err); Saved});//ortank.create ({size: ' small '}, function (err, small) { if (err) return Handlererror (err); Saved}}
Inquire
Model integrates several built-in static query methods, such as Find, FindByID, FindOne, where
Tank.find ({size: "small"}). WHERE ("CreatedDate"). GT (Oneyearago). exec (callback);
Delete
Model integrates the static Remove method
Tank.remove ({size: ' large '}, function (err) { if (err) return HandleError (err); removed;}),
Update
Each model has its own Update method, this method only updates without returning the model, if you like to return to model after updating using findoneandupdate
Mongoose Guide-Model