Should I Use Schema.Types.ObjectId or Schema.ObjectId When Defining a Mongoose Schema

前端 未结 4 747
温柔的废话
温柔的废话 2021-02-12 23:39

It seems like defining my Schema this way:

var PossessionSchema = new mongoose.Schema({
  thing: {type: mongoose.Schema.Types.ObjectId, ref:\"Thing\"}
});
         


        
4条回答
  •  野性不改
    2021-02-13 00:16

    There isn't much of a difference, but they are available for separate uses.

    Schemas should always use mongoose.Schema.Types.

    mongoose.Types are the object you work with within a mongoose document. These are special array subclasses, buffer subclasses, etc that we've hooked into or created special to ease updates and track changes.

    Source: https://github.com/Automattic/mongoose/issues/1671

提交回复
热议问题