Model()
Parameters
doc «Object» values for initial set
optional «[fields]» object containing the fields that were selected in the query which returned this document. You do not need to set this parameter to ensure Mongoose handles your query projection.
[skipId=false] «Boolean» optional boolean. If true, mongoose doesn’t add an
_id
field to the document.
Inherits:
A Model is a class that’s your primary tool for interacting with MongoDB. An instance of a Model is called a Document.
In Mongoose, the term “Model” refers to subclasses of the mongoose.Model
class. You should not use the mongoose.Model
class directly. The mongoose.model()
and connection.model()
functions create subclasses of mongoose.Model
as shown below.
Example:
// `UserModel` is a "Model", a subclass of `mongoose.Model`.
const UserModel = mongoose.model('User', new Schema({ name: String }));
// You can use a Model to create new documents using `new`:
const userDoc = new UserModel({ name: 'Foo' });
await userDoc.save();
// You also use a model to create queries:
const userFromDb = await UserModel.findOne({ name: 'Foo' });