我嘗試使用模式的實體方法 但是失敗了 它顯示,不是函式 誰能給我解釋一下
const bookSchema =new schema(
{
name : String ,
Author : String 。
}
);
const Model = mongoose.model;
const bookModel = Model('book',bookSchema)。
bookSchema.methods.getName = function(){
return ('the name of book is ' this. name 'the name of book author is ' this.Author>)。)
}
const Nodejs =new bookModel({name: 'Node. js書' ,Author:'Me'})。
const Authorname = Nodejs.getName()。
console.log(AuthorName)。
uj5u.com熱心網友回復:
const bookSchema = new schema(
{
name : String ,
Author : String 。
}
);
const bookModel = mongoose.model( Book',bookSchema);
let GreenTrees = new bookModel({ name: 'GoodBook', Author: 'Frogs' })。)
console.log(`the name of book is ${GreenTrees.get(name)} The name of book
作者是${GreenTrees.get(Author)}`)。)
let yourBook = new bookModel({name:'Node. js書' ,Author:'Me'})。
let Authorname = yourBook.get(Author)。
console.log(AuthorName)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/331064.html
標籤:
