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


TypeScript Schema.static方法代码示例

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


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

示例1:

  },
  create: {
    type: Date,
    "default": Date.now
  },
  description: {
    type: String
  }
});

schema.static("updateAuthor", (author: {}, description: string) => {

  return Author
    .update({
      "_id": author
    }, {
      "$set": {
        "description": description
      }
    })
    .exec();
});

schema.static("updateByAge", (ageLimit: number, text: string) => {

  return Author
    .where("age")
    .gte(ageLimit)
    .update({
      "$set": {
        description: text
      }
开发者ID:vladotesanovic,项目名称:typescript-mongoose-express,代码行数:32,代码来源:model.ts

示例2: function

});
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());
});
schema.queue('m1', [1, 2, 3]).queue('m2', [[]]);
schema.remove('path');
schema.remove(['path1', 'path2', 'path3']);
schema.requiredPaths(true)[0].toLowerCase();
schema.set('key', 999).set('key');
schema.static('static', cb).static({
  s1: cb,
  s2: cb
});
schema.virtual('virt', {}).applyGetters({}, {});
schema.virtualpath('path').applyGetters({}, {});
/* static properties */
mongoose.Schema.indexTypes[0].toLowerCase();
mongoose.Schema.reserved.hasOwnProperty('');
/* inherited properties */
schema.addListener('e', cb);
/* practical examples */
var animalSchema = new mongoose.Schema({
  name: String,
  type: String
});
开发者ID:RaySingerNZ,项目名称:DefinitelyTyped,代码行数:31,代码来源:mongoose-tests.ts

示例3: Schema

import {Schema,Document,Model} from "mongoose";
import {getModels} from "./helpers";

export const RoomModelSchema = new Schema({
    model_id: {type: String, required: true},
    model_name: {type: String, required: true},
    sync_date: {type: Date, required: true}
});

RoomModelSchema.static("getModels",getModels);

export interface IRoomModel extends Document{
    model_name: string;
    Plan: Array<string>;
    count: number;
}

export interface IRoomModelModel extends Model<IRoomModel>{

    getModels: ( callback: (error: Error, data: {}) => void ) => void ;
}
开发者ID:chabbaboy,项目名称:objectsapi,代码行数:21,代码来源:schema.ts

示例4:

    guid: {type: String},
    complex: Schema.Types.Mixed,
    entity :  {type: String},
    model :  {type: String},
    category :  {type: String},
    group : {type: String},
    level : {type: String},
    space :  { type: String},
    data: Schema.Types.Mixed,
    checkouts: Schema.Types.Mixed,
    geometry: Schema.Types.Mixed,
    material: Schema.Types.Mixed,
});

BimSchema.static("getBims",getBims);
BimSchema.static("getBimsCount",getBimsCount);
BimSchema.static("getBimByGuid",getBimByGuid);
BimSchema.static("getBimComplex",getBimComplex);



export interface IBim extends  Document{
    guid: string;
    complex: Object;
    entity : string;
    model :  string;
    category :  string;
    group : string;
    level : string;
    space : string;
开发者ID:chabbaboy,项目名称:objectsapi,代码行数:30,代码来源:schema.ts

示例5: Schema

    // author_id?: string;
    author?: IUser| ObjectID;
    artist?: string;
    title: string;
    description?: string;
    videourl: string;
    thumbnailurl: string;
  }

  const videoSchema: Schema = new Schema({
    author: {type: Schema.Types.ObjectId, ref: 'User'},
    artist: {type: String},
    title: {type: String, required: true},
    description: {type: String},
    videourl: {type: String, required: true, unique: true},
    thumbnailurl: {type: String, required: true, unique: true}
  });

  videoSchema.static('findAll', function (cb: {(err: Error, videos: IVideo[]): void}): Promise<IVideo[]> {
    return this.find(cb);
  });

  videoSchema.static('findByAuthor', function (authorId: string, cb: {(err: Error, videos: IVideo[]): void}): Promise<IVideo[]> {
    return this.find({author: authorId}, cb);
  });

  export const Video: Model<IVideo> = mongoose.model<IVideo>('Video', videoSchema);
}

export = Video;
开发者ID:dadakoko,项目名称:play-server,代码行数:30,代码来源:video.ts

示例6: Schema

  export interface IUser extends Document {
    name: string;
    email: string;
    password: string;
  }

  const userSchema: Schema = new Schema({
    name: {type: String, required: true, unique: true},
    email: {type: String, required: true, unique: true},
    // we don't want the password to be fetched by default
    password: {type: String, required: true, select: false}
  });

  userSchema.static('findAll', function (cb: {(err: Error, user: IUser[]): void}) {
    return this.find(cb);
  });
  userSchema.static('authenticateUser', function (identifier: string, password: string, cb: {(err: Error, user?: IUser): void}) {
    // we need to ask mongoose for the password property this time ...
    this.find({$or: [{name: identifier}, {email: identifier}]}, {name: 1, email: 1, password: 1}, (findErr: Error, users) => {
      if (findErr) {
        cb(findErr);
        return;
      }
      if (users.length > 0) {
        // we assume that there is at most one user !
        let user: IUser = users[0];
        user.compare(password, (bcryptErr, isAuth) => {
          if (bcryptErr) {
            cb(bcryptErr);
            return;
开发者ID:dadakoko,项目名称:play-server,代码行数:30,代码来源:user.ts

示例7: function

let productSchema = new  mongoose.Schema({
    name: {type:String, required: true},
    brand: {type: String, required: true},
    category: {type: String, required: true},
    price: {type: Number, required: true}
});

productSchema.methods.getAll = function(cb) {
    return Product.find({}, cb);
};

productSchema.methods.getById = function(productId, cb) {
    return Product.find({ productId: this._id }, cb);
};

productSchema.static('findByName', function(productName, cb) {
    return this.model('Product').find({ productName: this.name }, cb);
});

productSchema.methods.create = function(product: IProduct) {
    let newProduct = new Product(product);
    newProduct.save(function(err) {
        if(err) {
            console.log(`error: ${err}`);
        }
        console.log('saved!')
    });
};

export const Product = mongoose.model('Product', productSchema);
开发者ID:jacobleesinger,项目名称:inventory_microsite,代码行数:30,代码来源:product.ts

示例8: findAllByAuthor

  author: {},
  description: string;
}

export interface IPostModel extends Model<IPost> {
  findAllByAuthor(id: string): Promise<IPost[]>
}

const schema = new Schema({
  title: String,
  create: {
    type: Date,
    "default": Date.now
  },
  author: {
    type: Schema.Types.ObjectId,
    ref: 'Author'
  },
  description: String
});

schema.static("findAllByAuthor", (author: string) => {

  return Post
    .find({ author: author })
    .lean()
    .exec();
});

export const Post = mongoose.model<IPost>("Post", schema) as IPostModel;
开发者ID:vladotesanovic,项目名称:typescript-mongoose-express,代码行数:30,代码来源:model.ts


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