【发布时间】:2021-04-21 21:58:51
【问题描述】:
const mongooseResponse = await mongoose.connect(mongoUri);
const game = await GameSchema.create({
image: "test",
title: "StarBurst"
})
GameSchema.findOne({title: "starburst"})
console.log(game)
我试图创建一个猫鼬模式来保存一些数据。这里我只是创建了一些测试数据。
但是当我使用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)
【问题讨论】:
标签: node.js mongodb typescript mongoose