本文整理汇总了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);
示例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});
示例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);
示例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;
示例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) {
示例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);
});
示例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);
示例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);
示例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){
示例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);