當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。