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

前端 未结 4 746
温柔的废话
温柔的废话 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-12 23:59

    The documentation says: "To specify a type of ObjectId, use Schema.Types.ObjectId in your declaration."... "or just Schema.ObjectId for backwards compatibility with v2".

    So I use "Schema.Types.ObjectId".

提交回复
热议问题