The Quick Start section of the documentation for Mongoose 5.0.15, including the main landing page of their website, shows no new
keyword when creating a Schema. When I click on the Schemas section of the documentation, it shows the new
keyword.
I am wondering if new
is required or not in 5.xx as the documentation is super inconsistent? It was used in 4.xx
Thanks
var kittySchema = mongoose.Schema({
name: String
})
VS
var kittySchema = new mongoose.Schema({
name: String
})
Generally, new
is required because without that you'd just be calling the Schema()
function, rather than construct a new instance of Schema
(latter is what you actually need).
BUT if you look at the source for schema.js, they return a new instance anyway, even if you call Schema()
as a direct function (ie without new
). So there would be no difference whether or not you use new
. You get a new Schema object either way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.