How to use the mongoose.Schema function in mongoose

To help you get started, we’ve selected a few mongoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cs-education / classTranscribe / new_app / server.js View on Github external
var RouteHandler = Router.RouteHandler;

var dbConfig = require('./dbConfig');
//var routes = require('./js/routes');

var devMode = true;


var mongoConnection = mongoose.createConnection(dbConfig.mongoURI, dbConfig.mongoConfig);
if(devMode) {
    mongoose.set('debug, true');
}
// Logging connection:
mongoConnection.on('error', console.error.bind(console, 'DB connection error.')).once('open', console.log.bind(console, 'DB Connection established.'));

var studentSchema = new mongoose.Schema({
    firstName : String,
    lastName  : String,
    email     : String,
    studentID : String,
    className : String
});

var Student = mongoConnection.model('Student', studentSchema);

var app = express();
app.set('views', __dirname + '/js/views');
app.set('view engine', 'jsx');
app.engine('jsx', reactViews.createEngine());
//app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(__dirname));
app.use(cookieParser());
github luckcoding / hotchcms / server / src / models / admin-group.model.js View on Github external
const mongoose = require('mongoose')
const { parse } = require('../lib/authority.lib')

/**
 * 管理员用户组
 */
const AdminGroupSchema = new mongoose.Schema(
  {
    // 名称
    name: { type: String, required: true, unique: true },

    // 备注
    description: String,

    // 管理等级
    gradation: {
      type: Number,
      mix: 0,
      max: 100,
      default: 0,
    },

    // 权限列表
github dekkerglen / CubeCobra / models / cube.js View on Github external
const mongoose = require('mongoose');

// Cube schema
const cubeSchema = mongoose.Schema({
  name: {
    type: String,
    required: true,
  },
  shortID: {
    type: String,
    required: true,
    index: true,
  },
  urlAlias: {
    type: String,
    index: true,
  },
  owner: {
    type: String,
    required: true,
github Andyliwr / upload-img / models / history.js View on Github external
import { User } from './user'
const mongoose = require('mongoose')

const historySchema = new mongoose.Schema({
    filename: String,
    old_filename: String,
    filesize: Number,
    userid: mongoose.Schema.ObjectId, // 所属人
    tmp_url: String, // 腾讯云临时地址
    remote_url: String, // 七牛永久地址
    time: Date
})

historySchema.statics.add = async function (history, needUpdateUser) {
    let a = await history.save()
    if (a) {
        if (needUpdateUser) {
            let b = await User.update({ _id: history.userid }, { '$addToSet': { history: history.id } })
            if (b.ok == 1 && b.nModified == 1) {
                return 1
github bulwark-crypto / bulwark-explorer / model / tx.js View on Github external
/**
 * The inputs for a tx.
 */
const TXIn = new mongoose.Schema({
  coinbase: { type: String },
  //sequence: { type: Number },
  txId: { type: String },
  vout: { type: Number },
  relatedVout: { required: false, type: RelatedVout },
  scriptSig: { required: false, type: ScriptSig }
}, { _id: false, versionKey: false });

/**
 * The outputs for a tx.
 */
const TXOut = new mongoose.Schema({
  address: { index: true, required: true, type: String },
  n: { required: true, type: Number },
  value: { required: true, type: Number }
}, { _id: false, versionKey: false });

/**
 * Setup the schema for transactions.
 */
const txSchema = new mongoose.Schema({
  __v: { select: false, type: Number },
  _id: mongoose.Schema.Types.ObjectId,
  //blockHash: { required: true, type: String },
  blockHeight: { index: true, required: true, type: Number },
  createdAt: { index: true, required: true, type: Date },
  txId: { index: true, required: true, type: String },
  version: { required: true, type: Number },
github gothinkster / node-express-realworld-example-app / models / Article.js View on Github external
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var slug = require('slug');
var User = mongoose.model('User');

var ArticleSchema = new mongoose.Schema({
  slug: {type: String, lowercase: true, unique: true},
  title: String,
  description: String,
  body: String,
  favoritesCount: {type: Number, default: 0},
  comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }],
  tagList: [{ type: String }],
  author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
}, {timestamps: true});

ArticleSchema.plugin(uniqueValidator, {message: 'is already taken'});

ArticleSchema.pre('validate', function(next){
  if(!this.slug)  {
    this.slugify();
  }
github scorelab / DroneSym / dronesym-node / Models / group.js View on Github external
var mongoose = require('mongoose');

var groupSchema = mongoose.Schema({
	name : {
		type: String,
		required: true
	},
	userId:{
		type: String,
		required: true
	},
	drones: {
		type: [String],
		default: []
	},
	users: {
		type : [{
			userId : String,
			userName : String
github jembi / openhim-core-js / src / model / autoRetry.js View on Github external
import { Schema } from 'mongoose'
import { connectionAPI, connectionDefault } from '../config'

const AutoRetrySchema = new Schema({
  transactionID: {
    type: Schema.Types.ObjectId, required: true
  },
  channelID: {
    type: Schema.Types.ObjectId, required: true
  },
  requestTimestamp: {
    type: Date, required: true
  }
})

export const AutoRetryModelAPI = connectionAPI.model('AutoRetry', AutoRetrySchema)
export const AutoRetryModel = connectionDefault.model('AutoRetry', AutoRetrySchema)
github andrelmlins / freesoccer / src / schemas / Stage.ts View on Github external
import { Document, Schema, Model, model } from 'mongoose';

import Match from './Match';
import { ICompetition } from './Competition';

export interface IStage extends Document {
  hash: string;
  name: string;
  goals: number;
  matchs: Match[];
  competition: ICompetition;
}

export var StageSchema: Schema = new Schema({
  hash: String,
  name: String,
  goals: Number,
  matchs: [Object],
  competition: { type: Schema.Types.ObjectId, ref: 'Competition' }
});

export const Stage: Model = model('Stage', StageSchema);