Mongoose Guide-Model

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.