當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mongoose.model函數代碼示例

本文整理匯總了TypeScript中mongoose.model函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript model函數的具體用法?TypeScript model怎麽用?TypeScript model使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了model函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: callback

			$addToSet: { following: to }
		}
	).exec(function (err) {
		if (err)
			return callback(err);

		callback(null, null);
	});
};

// authenticate input against database
OrderSchema.statics.unFollow = function (from, to, callback) {

	Order.update(
		{
			_id: from,
		},
		{
			$inc: { followingCount: -1 },
			$pull: { following: to }
		}
	).exec(function (err) {
		if (err)
			return callback(err);

		callback(null, null);
	});
};

export const Order = model('Order', OrderSchema);
開發者ID:Chegeek,項目名稱:TradeJS,代碼行數:30,代碼來源:order.ts

示例2:

                    zip: String,
                    website: String,
                    latitude: Number,
                    longitude: Number
                }
            },
            date: Date,
            category: String,
            content: String
        }
    ],
    books: [
        {
            id: Number,
            isbn10: Number,
            isbn13: Number,
            title: String,
            category: String
        }
    ]
}

// userSchema.method['comparePassword'] = function(candidatePassword: String, cb: Function) {
//     bcrypt.compare(candidatePassword, this.password, function(err: Error, isMatch: Boolean) {
//         if (err) return cb(err);
//         cb(null, isMatch);
//     });
// };

export let User: mongoose.Model<IUser> = mongoose.model<IUser>('User', userSchema);
開發者ID:uqutub,項目名稱:NodejsMySql,代碼行數:30,代碼來源:userModel.ts

示例3:

import * as mongoose from 'mongoose';

export interface IBlogModel extends app.i.IBlog, mongoose.Document{}


let blogSchema = new mongoose.Schema({
  title: { type: String, required: true },
  datePosted: { type: Number },
  body: { type: String, required: true },
  imageURL: { type: String, default: 'http://1.bp.blogspot.com/-Bsv5jXiALOk/UdXLHs5jwaI/AAAAAAAAIU0/JuhiK3PvL10/s541/kune-kune-piglets-stacked.jpg' },
  tags: String
});

export let Blog = mongoose.model<IBlogModel>('Blog', blogSchema);
開發者ID:triciatseng,項目名稱:expert-fortnight,代碼行數:14,代碼來源:Blog.ts

示例4: require

var mongoose = require('mongoose');


var ThingSchema = new mongoose.Schema({
    userid: {
        type: String,
        required: true
    },
    expireAt: {
        type: Date,
        required: true,
        default: function() {
        // 60 seconds from now
        return new Date(new Date().valueOf() + 7260000);
    }
    }
});

// Expire at the time indicated by the expireAt field
ThingSchema.index({ expireAt: 1 }, { expireAfterSeconds : 0 });

export = mongoose.model('Recovery', ThingSchema);
開發者ID:SocialMovieNetwork,項目名稱:SMP-Final,代碼行數:22,代碼來源:recovery.model.ts

示例5: function

PlatformSchema.pre('save', function(next: Function): void {
  let user = this

  // generate a salt then run callback
  if (user.isNew) {
    bcrypt
    .genSalt(10, (err: Error, salt: string) => {
      if (err) { return next(err) }

      // encrypt password with salt
      bcrypt.hash(user.password, salt, null, (err, hash) => {
        if (err) { return next(err) }

        // overwrite plain text password with encrypted password
        user.password = hash

        next()
      })
    })
  } else {
    UTIL.setUpdateTime(user, ['username', 'password', 'nickname', 'name', 'gender', 'mobile', 'email', 'pid', 'avatar', 'background', 'locale', 'city', 'country'])
    user.wasNew = user.isNew

    next()
  }
})

export { IPlatform }

export default model<IPlatform>('Platform', PlatformSchema)
開發者ID:yeegr,項目名稱:SingularJS,代碼行數:30,代碼來源:PlatformModel.ts

示例6: Schema

import { Schema, model } from 'mongoose';
const JobSchema = new Schema({
    companyName: {type: String, required: true},
    fantasyName: {type: String, required: true},
    cnpj: {type: String, required: true},
    showCompanyName: Boolean,
    opportunityName: {type: String, required: true},
    opportunityDecription: {type: String, required: true},
    howToSubscribe: {type: String, required: true},
    contact: {
        email: {type: String, required: true},
        name: {type: String, required: true},
        phone: {type: String, required: true}
    },
    salaryRange: {type: String, required: true},
    opportunityType: {type: String, required: true},
    contractType: {type: String, required: true},
    city: {type: String, required: true},
    state: {type: String, required: true}
});
export const Job = model('Job', JobSchema);
開發者ID:giggio,項目名稱:transempregos-portal,代碼行數:21,代碼來源:job.ts

示例7: before

 before((done) => {
     User = mongoose.model("User");
     user = new User();
     done();
 })
開發者ID:cm0s,項目名稱:mea2n,代碼行數:5,代碼來源:user.model.spec.ts

示例8:

import * as mongoose from 'mongoose';

export interface ICommentModel extends app.i.IComment, mongoose.Document{}

let commentSchema = new mongoose.Schema({
    message: {type: String, required: true},
    datePosted: Number,
    user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
    event: {type: mongoose.Schema.Types.ObjectId, ref: 'Event', required: true}
});

export let Comment = mongoose.model<ICommentModel>('Comment', commentSchema);
開發者ID:aurbina83,項目名稱:VC,代碼行數:12,代碼來源:model.ts

示例9:

import * as mongoose from 'mongoose';

export interface ITodoModel extends ITodo, mongoose.Document { }

let todoSchema = new mongoose.Schema({
  task: String,
  status: String,
});

export let Todo = mongoose.model('Todo', todoSchema);
開發者ID:benstelzer,項目名稱:test,代碼行數:10,代碼來源:testing.model.ts

示例10: cb

        let user: IUser = users[0];
        user.compare(password, (bcryptErr, isAuth) => {
          if (bcryptErr) {
            cb(bcryptErr);
            return;
          }
          if (isAuth) {
            // remove the password from the fetched object
            delete user.password;
            cb(undefined, user);
            return;
          } else {
            cb(undefined, undefined);
          }
        });
      } else {
        cb(undefined, undefined);
      }
    });
  });
  
  userSchema.method('compare', function (password: string, cb: {(err: Error, isValid: boolean): void}): void {
    console.log('compare');
    bcrypt.compare(password, this.password, cb);
  });

  export const User: Model<IUser> = mongoose.model<IUser>('User', userSchema);

}
export = User;
開發者ID:dadakoko,項目名稱:play-server,代碼行數:30,代碼來源:user.ts


注:本文中的mongoose.model函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。