本文整理汇总了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);
示例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);
示例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);
示例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);
示例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)
示例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);
示例7: before
before((done) => {
User = mongoose.model("User");
user = new User();
done();
})
示例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);
示例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);
示例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;