• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript mongoose.Schema函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中mongoose.Schema函数的典型用法代码示例。如果您正苦于以下问题:TypeScript Schema函数的具体用法?TypeScript Schema怎么用?TypeScript Schema使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Schema函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1:

import * as mongoose from 'mongoose';

const _todoSchema = {
    todoMessage: {type: String, required: true, trim: true},
    createdAt: {type: Date, default: Date.now}
}

export default mongoose.Schema(_todoSchema);
开发者ID:Kablex,项目名称:generator-ng-fullstack,代码行数:8,代码来源:todo-model.ts


示例2:

  nextVersion: {type:Number, default:1},
  publish: {type:Boolean, default:false},
  userPermissions: {type:[ObjectId], default:[], validate:isObjectIdArray},
  groupPermissions: {type:[ObjectId], default:[], validate:isObjectIdArray},
  derivedUserPermissions: {type:[ObjectId], default:[], validate:isObjectIdArray},
  derivedGroupPermissions: {type:[ObjectId], default:[], validate:isObjectIdArray},
  content: String,
  lastModifiedTime: {type: Date, default: Date.now, index:true},
  isPublic: {type: Boolean, default: false}
});
export var Page = mongoose.model("Page",PageSchema);

var PageVersionSchema = mongoose.Schema({
  pageId: {type:ObjectId, index:true, required:true, validate:isObjectId},
  version: {type: Number, index:true, required:true},
  editorIds:{type:[ObjectId], index:true, validate:isObjectIdArray},
  content:{type:String},
  timestamp: {type: Date, default: Date.now, index:true}
});
export var PageVersion = mongoose.model("PageVersion",PageVersionSchema);

var UserSchema = mongoose.Schema({
  username: {type:String, index:true, unique:true, required:true},
  fullName: {type:String, index:true},
  email: {type:String, index:true, required:true},
  groups: {type:[ObjectId], default: [], validate:isObjectIdArray},
  lastLoginTime: {type:Date, default:null},
  fromLdap: {type:Boolean, required:true},
  watchedPageIds: {type:[ObjectId], default:[]}
});
UserSchema.index({firstName:1, lastName:1});
开发者ID:MisterTea,项目名称:TidalWave,代码行数:31,代码来源:model.ts


示例3:

"use strict";

import * as mongoose from "mongoose";

const _todoSchema = {
    todoMessage: {type: String, required: true, trim: true},
    createdAt: {type: Date, default: Date.now}
}

module.exports = mongoose.Schema(_todoSchema);
开发者ID:bernardbr,项目名称:generator-ng-fullstack,代码行数:10,代码来源:todo-model.ts


示例4: require

// Requires
const port = 8080;
const mongodbUrl = 'mongodb://localhost:27017/vip';
const http = require('http');
const url = require('url');
const fs = require('fs');
//const io = require('socket.io');
const mongoose = require('mongoose');
mongoose.connect(mongodbUrl);


// ConnectedMember model
const connectedMemberSchema = mongoose.Schema({
	name: String,
	order: Number,
	connected_at: Date
});
/*connectedMemberSchema.statics.findByName = function(name, cb) {
  return this.find({ name: name }, cb);
};*/
const ConnectedMember = mongoose.model('ConnectedMember', connectedMemberSchema);


// const MongoClient = require('mongodb').MongoClient;
// const assert = require('assert');
// const uuid = require('node-uuid');


const server = http.createServer(function (request, response) {
	var path = url.parse(request.url).pathname;
开发者ID:marqu3s,项目名称:vanhack-interview-practice,代码行数:30,代码来源:server.ts


示例5: require

var mongoose = require('mongoose');
//var cheerio = require('cheerio')
//var path = './data';
mongoose.connect('mongodb://192.168.199.111/weibo');

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function (callback) {
    console.log('connected to MongoDB');
});

var areaSchema = mongoose.Schema({
    created_at: { type: Date, default: Date.now },
    updated_at: { type: Date, default: Date.now },
    area_id: Number,
    title: String,
    geo: {
        lat: Number,
        lon: Number
    }
},{ collection: 'area' });

var Area = mongoose.model('AREA', areaSchema);

//insertWeiboDate('./datas/B2094757D06EAAF4409D.json');
//var fileList = fs.readdirSync(path);
//fileList.forEach(function (item) {
//    console.log(path + '/' + item);
//    insertWeiboDate(path + '/' + item);
//});

//function insertWeiboDate(filename) {
开发者ID:cheneason,项目名称:getPoisFromWeibo,代码行数:32,代码来源:app.ts


示例6: function

//Middleware
app.use(express.static(path.join(__dirname,'./public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(session({
  genid: function(req) {
    return (Date.now().toString()) // use UUIDs for session IDs 
  },
  secret: '123456789'
}));


var userSchema=mongoose.Schema({
    "firstname":String,
    "lastname":String,
    "email":{type:String,unique:true},
    "password":{type:String},
    "createdOn":{type:Date,default:Date.now()}
})

mongoose.model('Users',userSchema);
var User=mongoose.model('Users',userSchema);

var myDocument = new User();

mongoose.connection.on('connected',function(){
    console.log("Database connected");
});
mongoose.connection.on('error',function(err){
    console.log(err);
});
开发者ID:Parkash067,项目名称:My_drive,代码行数:31,代码来源:app.ts


示例7: require

'use strict';

let mongoose = require('mongoose');

let schema = mongoose.Schema({
  name: {type: String, index: true},
  location: {
    type: {type: String},
    coordinates: [Number]
  }
});

schema.index({location: '2dsphere'});

/**
 *
 * @param filter Object with filter conditions
 * @param skip Number of rows skipped
 * @param limit Number of rows
 * @param sort Sort expression
 * @param select Field names to include, space separated
 * @return {Promise<any>}
 */
schema.statics.list = function (filter?:any,
                                skip?:number, limit?:number,
                                sort?:string, select?:string):Promise<any> {
  try {
    let query = Product.find(filter);
    query.sort(sort);
    query.skip(skip);
    query.limit(limit);
开发者ID:Toktik,项目名称:node-seed,代码行数:31,代码来源:Product.ts


示例8:

'use strict';

import mongoose from 'mongoose';
const Types = mongoose.Schema.Types;

const Schema = mongoose.Schema({
  token: {
    type: String,
    required: [true, 'Token is required.']
  },

  user: {
    type: Types.ObjectId,
    ref: 'user',
    required: [true, 'User is required.']
  }

}, {
  toObject: {
    virtuals: true
  },
  toJSON: {
    virtuals: true
  },
  timestamps: true
});

export default mongoose.model('remember-token', Schema);
开发者ID:HallM,项目名称:poc-fw2,代码行数:28,代码来源:remember-token.ts


示例9:

const db = mongo.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {
    console.log('db connected');
});

const userSchema = mongo.Schema({
    username: String,
    gender: String,
    name: {
        title: String,
        first: String,
        last: String
    },
    location: {
        street: String,
        city: String,
        state: String,
        zip: Number
    },
    picture:{
        large: String,
        medium: String,
        thumbnail: String
    }
});

userSchema.virtual('name.full').get(function () {
    return _.startCase(this.name.first + ' ' + this.name.last);
});

userSchema.virtual('name.full').set(function(value){
开发者ID:wpcfan,项目名称:calltalent_server,代码行数:32,代码来源:db.ts


示例10:

'use strict';

import mongoose from 'mongoose';

const Schema = mongoose.Schema({
  email: {
    type: String,
    unique: true,
    required: [true, "Email is required."]
  },

  failedCount: {
    type: Number,
    default: 0
  },

  lockedUntil: {
    type: Date
  }
}, {
  toObject: {
    virtuals: true
  },
  toJSON: {
    virtuals: true
  },
  timestamps: true
});

export default mongoose.model('login-locker', Schema);
开发者ID:HallM,项目名称:poc-fw2,代码行数:30,代码来源:login-locker.ts



注:本文中的mongoose.Schema函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mongoose.connect函数代码示例发布时间:2022-05-25
下一篇:
TypeScript mongojs.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap