gpt4 book ai didi

mongoose - Artist.findOne不是函数

转载 作者:行者123 更新时间:2023-12-03 12:35:04 25 4
gpt4 key购买 nike

我在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 });
};

我肯定安装了 Mongoose ,但似乎我不再适本地导入 Mongoose 或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;

最佳答案

我发现module.exports文件上的models/artist.js错误。

代替:

// const Artist = mongoose.model('artist', ArtistSchema);

// module.exports = ArtistSchema;

应该是这样的:
module.exports = mongoose.model('artist', ArtistSchema);

关于mongoose - Artist.findOne不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53937933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com