本文整理汇总了TypeScript中mongoose.Mongoose类的典型用法代码示例。如果您正苦于以下问题:TypeScript Mongoose类的具体用法?TypeScript Mongoose怎么用?TypeScript Mongoose使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mongoose类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: configureMongoose
export function configureMongoose() {
const mongoose = new Mongoose();
mongoose.connect(process.env.MONGODB_URL, function(err) {
if(err) { throw err; }
console.log("Successfully connected to mongodb");
});
return mongoose;
}
开发者ID:kaka3004,项目名称:cms,代码行数:12,代码来源:mongoose-config.ts
示例2: configureMongoose
export function configureMongoose() {
const mongoose = new Mongoose();
mongoose.connect('mongodb://127.0.0.1/goodsense', function(err) {
if(err) { throw err; }
console.log("Successfully connected to mongodb");
});
return mongoose;
}
开发者ID:dghijben,项目名称:dashboard,代码行数:12,代码来源:mongoose.config.ts
示例3: configureSprintModel
export function configureSprintModel(mongoose: Mongoose) {
var sprintSchema = new Schema({
from_date: Date,
to_date: Date,
project: {type: String, ref: 'Project'}
});
sprintSchema.method('replaceAttributes', function(attributes) {
this.from_date = attributes.from_date;
this.to_date = attributes.to_date;
this.project = MongooseUtils.id(attributes.project);
});
sprintSchema.method('updateAttributes', function(attributes) {
if(attributes.from_date) {
this.from_date = attributes.from_date;
}
if(attributes.to_date) {
this.to_date = attributes.to_date;
}
if(attributes.project) {
this.project = MongooseUtils.id(attributes.project);
}
});
sprintSchema.plugin(timestampsPlugin);
sprintSchema.plugin(promisifyPlugin);
SprintModel = mongoose.model<ISprintDocument>('Sprint', sprintSchema);
}
开发者ID:dghijben,项目名称:dashboard,代码行数:30,代码来源:SprintModel.ts
示例4: configureTaskModel
export function configureTaskModel(mongoose: Mongoose) {
var taskSchema = new Schema({
title: String,
description: String,
assigned_to: {type: String, ref: 'User'}
});
taskSchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.description = attributes.description;
this.assigned_to = MongooseUtils.id(attributes.assigned_to);
});
taskSchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.description) {
this.description = attributes.description;
}
if(attributes.assigned_to) {
this.assigned_to = attributes.assigned_to;
}
});
taskSchema.plugin(timestampsPlugin);
taskSchema.plugin(promisifyPlugin);
TaskModel = mongoose.model<ITaskDocument>('Task', taskSchema);
}
开发者ID:dghijben,项目名称:dashboard,代码行数:30,代码来源:TaskModel.ts
示例5: configureStoryModel
export function configureStoryModel(mongoose: Mongoose) {
var storySchema = new Schema({
title: String,
description: String
});
storySchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.description = attributes.description;
});
storySchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.description) {
this.description = attributes.description;
}
});
storySchema.plugin(timestampsPlugin);
storySchema.plugin(promisifyPlugin);
StoryModel = mongoose.model<IStoryDocument>('Story', storySchema);
}
开发者ID:kareem3d,项目名称:redux-typescript-nodejs,代码行数:26,代码来源:story-model.ts
示例6: configureProjectModel
export function configureProjectModel(mongoose: Mongoose) {
var projectSchema = new Schema({
title: String,
description: String
});
projectSchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.description = attributes.description;
});
projectSchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.description) {
this.description = attributes.description;
}
});
projectSchema.plugin(timestampsPlugin);
projectSchema.plugin(promisifyPlugin);
ProjectModel = mongoose.model<IProjectDocument>('Project', projectSchema);
}
开发者ID:dghijben,项目名称:dashboard,代码行数:25,代码来源:ProjectModel.ts
示例7: configureStoryModel
export function configureStoryModel(mongoose: Mongoose) {
var storySchema = new Schema({
title: String,
description: String,
project: {type: String, ref: 'Project'},
sprint: {type: String, ref: 'Sprint'}
});
storySchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.description = attributes.description;
this.project = MongooseUtils.id(attributes.project);
this.sprint = MongooseUtils.id(attributes.sprint);
});
storySchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.description) {
this.description = attributes.description;
}
});
storySchema.plugin(timestampsPlugin);
storySchema.plugin(promisifyPlugin);
StoryModel = mongoose.model<IStoryDocument>('Story', storySchema);
}
开发者ID:dghijben,项目名称:dashboard,代码行数:30,代码来源:StoryModel.ts
示例8: configureUserModel
export function configureUserModel(mongoose: Mongoose) {
var userSchema = new Schema({
firstName: String,
lastName: String,
email: String,
hashedPassword: String,
type: Number
});
userSchema.plugin(timestampsPlugin);
userSchema.plugin(promisifyPlugin);
userSchema.method('replaceAttributes', function(attributes) {
throw new Error("Not implemented");
});
userSchema.method('updateAttributes', function(attributes) {
throw new Error("Not implemented");
});
userSchema.method('hashPassword', function(password) {
this.hashedPassword = md5(password);
});
userSchema.method('checkPassword', function(password) {
return this.hashedPassword === md5(password);
});
const md5 = (password) => crypto.createHash('md5').update('"'+password+'"').digest('hex');
UserModel = mongoose.model<IUserDocument>('User', userSchema);
}
开发者ID:dghijben,项目名称:dashboard,代码行数:33,代码来源:UserModel.ts
示例9: configureCategoryModel
export function configureCategoryModel(mongoose: Mongoose) {
let categoryImageSchema = {
src: String,
width: Number,
height: Number,
kind: {type: String, enum: ['cover', 'main']},
};
let categorySchema = new Schema({
title: String,
slug: String,
status: String,
description: String,
images: [categoryImageSchema]
});
categorySchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.slug = attributes.slug;
this.status = attributes.status;
this.description = attributes.description;
this.images = attributes.images;
});
categorySchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.slug) {
this.slug = attributes.slug;
}
if(attributes.status) {
this.status = attributes.status;
}
if(attributes.description) {
this.description = attributes.description;
}
if(attributes.cover_image) {
this.cover_image = this.cover_image.concat(attributes.cover_image);
}
});
categorySchema.plugin(timestampsPlugin);
categorySchema.plugin(promisifyPlugin);
CategoryModel = mongoose.model<ICategoryDocument>('Category', categorySchema);
}
开发者ID:kaka3004,项目名称:cms,代码行数:52,代码来源:category-model.ts
示例10: configureShopModel
export function configureShopModel(mongoose: Mongoose) {
let addressSchema = {
address: String,
address2: String,
city:String,
state: String,
country: String,
country_code: String,
zip: String
};
let shopSchema = new Schema({
name: String,
published: Boolean,
config: {
address: addressSchema,
currency_code: String
},
creator_id: {type: Schema.Types.ObjectId, ref: 'User', required: true}
});
shopSchema.method('replaceAttributes', function(attributes) {
this.published = attributes.published;
this.config = attributes.config;
});
shopSchema.method('updateAttributes', function(attributes) {
if(attributes.published) {
this.published = attributes.published;
}
if(attributes.config) {
this.config = attributes.config;
}
});
shopSchema.method('setCreator', function(creator) {
this.creator_id = getDocumentId(creator);
});
shopSchema.plugin(timestampsPlugin);
shopSchema.plugin(promisifyPlugin);
ShopModel = mongoose.model<IShopDocument>('Shop', shopSchema);
}
开发者ID:kaka3004,项目名称:cms,代码行数:45,代码来源:shop-model.ts
注:本文中的mongoose.Mongoose类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论