我正在尝试使用Mongoose创建数据库,但是我不知道如何运行它/将其从代码推送到rot 3t。我使用的是上一课中的代码,当我删除具有相同名称的数据库时,无法再创建它。
var mongoose = require("mongoose");
// Save a reference to the Schema constructor
var Schema = mongoose.Schema;
// Using the Schema constructor, create a new UserSchema object
// This is similar to a Sequelize model
var ArticleSchema = new Schema({
// `title` is required and of type String
title: {
type: String,
required: true
},
// `link` is required and of type String
link: {
type: String,
required: true
},
// `note` is an object that stores a Note id
// The ref property links the ObjectId to the Note model
// This allows us to populate the Article with an associated Note
note: {
type: Schema.Types.ObjectId,
ref: "Note"
}
});
// This creates our model from the above schema, using mongoose's model method
var Article = mongoose.model("Article", ArticleSchema);
// Export the Article model
module.exports = Article;
我想解释如何使用此代码创建新集合