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


TypeScript Schema.index方法代码示例

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


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

示例1: before

  before((done: MochaDone) => {
    let schema = new mongoose.Schema({
      name: { type: String }
    });
    schema.index({ name: 'text' });
    testModel = mongoose.model('testSearchModel', schema);

    testServer
      .create({ resources: [testModel] })
      .then((createdServer: testServer.Server) => {
        server = createdServer;
        done();
      })
      .catch(done);
  });
开发者ID:apelade,项目名称:hapi-mongoose,代码行数:15,代码来源:search.ts

示例2:

    rate: number;
    cc: string;
    exchangedate:Date;
}

export interface ICurrency extends mongoose.Document, ICurrencyProps {

}

export const CurrencySchema: mongoose.Schema = new mongoose.Schema({
    txt: {
        type: String,
        required: true
    },
    rate: {
        type: Number,
        required: true
    },
    cc: {
        type: String,
        required: true
    },
    exchangedate:Date
}, {timestamps: true});

CurrencySchema.plugin(require("mongoose-paginate"));
CurrencySchema.index({cc: 1});
/**
 * METHODS
 */
export const CurrencyModel: IModel<ICurrency> = mongoose.model<ICurrency>("Currency", CurrencySchema);
开发者ID:ZulusK,项目名称:Budgetarium,代码行数:31,代码来源:Currencies.ts

示例3: function

    stuff: { type: String, lowercase: true, trim: true }
  }
});
schema.add({
  mixedArray: {
    type: [mongoose.Schema.Types.Mixed],
    required: true
  }
}, 'prefix');
schema.eachPath(function (path, type) {
  path.toLowerCase();
  type.sparse(true);
}).eachPath(cb);
schema.get('path');
schema.index({
  name: 1,
  binary: -1
}).index({}, {});
schema.indexes().slice();
schema.method('name', cb).method({
  m1: cb,
  m2: cb
});
schema.path('a', mongoose.Schema.Types.Buffer).path('a');
schema.pathType('m1').toLowerCase();
schema.plugin(function (schema, opts) {
  schema.get('path');
  opts.hasOwnProperty('');
}).plugin(cb, {opts: true});
schema.post('post', function (doc) {}).post('post', function (doc, next) {
  next(new Error());
});
开发者ID:RaySingerNZ,项目名称:DefinitelyTyped,代码行数:32,代码来源:mongoose-tests.ts

示例4: require

var mongoose = require('mongoose');


var ThingSchema = new mongoose.Schema({
    userid: {
        type: String,
        required: true
    },
    expireAt: {
        type: Date,
        required: true,
        default: function() {
        // 60 seconds from now
        return new Date(new Date().valueOf() + 7260000);
    }
    }
});

// Expire at the time indicated by the expireAt field
ThingSchema.index({ expireAt: 1 }, { expireAfterSeconds : 0 });

export = mongoose.model('Recovery', ThingSchema);
开发者ID:SocialMovieNetwork,项目名称:SMP-Finaler,代码行数:22,代码来源:recovery.model.ts

示例5: createSalt

    algorithm: {
        type: String,
        select: false
    },
    role: {
        type: String,
        enum: ['none', 'admin'],
        default: 'none'
    },
    created: Date,
    modified: Date,
});

UserSchema.index({
    'username': 1,
    'name.first': 1,
    'name.last': 1
});

function createSalt() {
    return crypto.randomBytes(16).toString('hex');
}

function hashPassword(password, salt, algorithm) {
    var hash = crypto.createHash(algorithm);
    hash.update(salt + password);
    return hash.digest('hex');
}

UserSchema.methods.validPassword = function(password) {
    return this.password === hashPassword(password, this.salt, this.algorithm);
开发者ID:sjohnsonaz,项目名称:build-launchpad,代码行数:31,代码来源:UserModel.ts

示例6: Schema

  description?: string;
}

export interface StoryInterface extends StoryProps, Document {}

const StorySchema: Schema = new Schema(
  {
    name: {
      type: String,
      minlength: 3,
      maxlength: 255,
      required: true
    },
    owner: {
      type: Schema.Types.ObjectId,
      required: true
    },
    description: {
      type: String
    }
  },
  { timestamps: true }
);

StorySchema.index({ owner: 1, name: 1 });

export const StoryModel: Model<StoryInterface> = model<StoryInterface>(
  "Story",
  StorySchema
);
开发者ID:trflagg,项目名称:bargie,代码行数:30,代码来源:story.ts

示例7: Schema

export interface MessageInterface extends MessageProps, Document {}

const MessageSchema = new Schema(
  {
    name: {
      type: String,
      minlength: 3,
      maxlength: 255,
      uppercase: true,
      required: true
    },
    text: String,
    story: {
      type: Schema.Types.ObjectId,
      required: true,
      ref: "Story"
    },
    compiledSource: String,
    messagesLoaded: [Schema.Types.ObjectId]
  },
  { timestamps: true }
);

MessageSchema.index({ story: 1, name: 1 }, { unique: true });

export const MessageModel: Model<MessageInterface> = model<MessageInterface>(
  "Message",
  MessageSchema
);
开发者ID:trflagg,项目名称:bargie,代码行数:29,代码来源:message.ts

示例8: next

/**
 * name - имя пользователя
 * lastname - фамилия пользователя
 * regDate - дата регистрации
 * login - логин
 * pass - пароль
 */
const userSchema = new mongoose.Schema({
  lastname: { type: String, required: true, validate: [nameValidator, nameValidationErrorText] },
  login: { type: String, required: true, unique: true, validate: [loginValidator, loginValidationErrorText] },
  name: { type: String, required: true, validate: [nameValidator, nameValidationErrorText] },
  pass: { type: String, required: true, validate: [passValidator, passValidationErrorText] },
  regDate: { type: Date, required: true },
});

userSchema.index({ name: 'text', lastname: 'text' });

/** Cохраняем не пароль, а его хеш, используя bcrypt */
userSchema.pre<IUserDocument>('save', async function(next) {
  if (!this.isModified('pass')) {
    return next();
  }

  try {
    const salt = await bcrypt.genSalt();
    this.pass = await bcrypt.hash(this.pass, salt);

    return next();
  } catch (err) {
    return next(err);
  }
开发者ID:dmikheev,项目名称:js-test-social-network,代码行数:31,代码来源:user.ts

示例9: it

  it('should process a complex example', () => {
    const nestedSchema = new Schema(
      {
        thing: {
          type: Schema.Types.ObjectId,
          ref: 'Thing',
        },
      },
      {},
    );

    const nestedItemSchema = new Schema(
      {
        user: {
          type: Schema.Types.ObjectId,
          ref: 'User',
          required: true,
        },
        priority: {
          type: Number,
          required: true,
          default: 0,
        },
      },
      {
        _id: false,
        id: false,
      },
    );

    const mainSchema: any = new Schema(
      {
        name: {
          type: String,
          required: true,
          index: true,
          placeholder: 'PLACEHOLDER_NAME',
        },
        referencedDocument: {
          type: Schema.Types.ObjectId,
          ref: 'RefDoc',
          immutable: true,
          required: true,
        },
        stringOptionsWithDefault: {
          type: String,
          required: true,
          default: 'defaultVal',
          enum: ['defaultVal', 'Option2'],
        },
        setting_type: {
          type: String,
        },
        setting_value: {
          type: Number,
          min: 0,
          validate: function validate(val: any) {
            if (this.setting_type === 'foo') {
              if (val > 1) {
                return false;
              }
            }
            return true;
          },
        },
        enabled: {
          type: Boolean,
          required: true,
          default: false,
        },
        nestedSchema: nestedSchema,
        nestedInline: {
          prop: {
            type: Number,
            required: true,
          },
        },
        nestedEmptyInline: {},
        nestedItems: {
          type: [nestedItemSchema],
        },
      },
      {
        strict: true,
      },
    );

    mainSchema.foo = 'bar';
    mainSchema.searchable = true;
    mainSchema.index({
      name: 'text',
    });

    const input = generateInterface('MainInterface', mainSchema);

    const output = `interface IMainInterfaceINestedSchema {
	thing?: string;
	_id?: string;
}

//.........这里部分代码省略.........
开发者ID:JamesHenry,项目名称:mongoose-schema-to-typescript-interface,代码行数:101,代码来源:generate-interface.spec.ts

示例10:

import * as mongoose from 'mongoose';
const NAME = 'Bet';

var schema = new mongoose.Schema({
    userId: {type: 'objectId', required: true},
    leagueId: {type: 'objectId', required: true},
    matchDay: {type: 'number', required: true},
    matches: [{
        _id: {type: 'objectId', required: true},
        result: {
            goalsHomeTeam: {type: 'number', required: true},
            goalsAwayTeam: {type: 'number', required: true}
        }
    }]
}, {autoIndex: false});

schema.index({userId: 1, leagueId: 1, matchDay: 1}, {unique: true});

var Bet = mongoose.model(NAME, schema);

export default Bet;
开发者ID:alehkleuzhyts,项目名称:forecast-fc,代码行数:21,代码来源:League.ts


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