const mongooseResponse = await mongoose.connect(mongoUri);
const game = await GameSchema.create({
image: "test",
title: "StarBurst"
})
GameSchema.findOne({title: "starburst"})
console.log(game)我尝试创建一个mongoose模式来保存一些数据。在这里,我只创建一些测试数据。
但是当我在指定标题的地方使用findOne时出现错误。
它给出了以下错误:
Type 'string' is not assignable to type 'Condition<{ type: String; unique: true; required: true; index: true; }> | undefined'.
下面是我创建模式的方式:
import { Document, model, Schema } from "mongoose";
export type GameModel = Document & {
image: {type: String},
title: {type: String, unique: true, required: true, index: true},
rank: {type: Number},
providerAmount: {type: Number},
nestedValues: [
{RTP: {type: String}},
{"Max Win": {type: String}},
{"Min Bet": {type: String}},
{Volatility: {type: String}},
{Betways: {type: String}},
{Release: {type: String}},
{Devices: {type: String}}
]
}
const GameSchema: Schema = new Schema({
image: {type: String},
title: {type: String, unique: true, required: true, index: true},
rank: {type: Number},
providerAmount: {type: Number},
nestedValues: [
{RTP: {type: String}},
{"Max Win": {type: String}},
{"Min Bet": {type: String}},
{Volatility: {type: String}},
{Betways: {type: String}},
{Release: {type: String}},
{Devices: {type: String}}
]
})
export default model<GameModel>('Game', GameSchema)发布于 2021-01-17 20:29:09
你必须使用模型,而不是模式:
const game = await GameModel.create({
image: "test",
title: "StarBurst"
})
let result = await GameModel.findOne({title: "starburst"})
console.log(game)https://stackoverflow.com/questions/65760377
复制相似问题