当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mongoose.Schema函数代码示例

本文整理汇总了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;未经允许,请勿转载。