在FindArtist.js
文件中运行此代码时,我在Electron应用程序中遇到错误:
const Artist = require('../models/artist');
/**
* Finds a single artist in the artist collection.
* @param {string} _id - The ID of the record to find.
* @return {promise} A promise that resolves with the Artist that matches the id
*/
module.exports = _id => {
return Artist.findOne({ _id: _id });
};
我肯定安装了猫鼬,但似乎我不再适当地导入猫鼬或Artist模型?不确定。
这是models/artist.js
文件:
const mongoose = require('mongoose');
const AlbumSchema = require('./album');
const Schema = mongoose.Schema;
const ArtistSchema = new Schema({
name: String,
age: Number,
yearsActive: Number,
image: String,
genre: String,
website: String,
netWorth: Number,
labelName: String,
retired: Boolean,
albums: [AlbumSchema]
});
const Artist = mongoose.model('artist', ArtistSchema);
module.exports = ArtistSchema;
答案 0 :(得分:1)
我发现module.exports
文件中的models/artist.js
是错误的。
代替:
// const Artist = mongoose.model('artist', ArtistSchema);
// module.exports = ArtistSchema;
应该是这样:
module.exports = mongoose.model('artist', ArtistSchema);