Mongoose 猫鼬嵌套别名
我在MongoDB中有以下字段,无法更改DB的模式Mongoose 猫鼬嵌套别名,mongoose,graphql,mongoose-schema,Mongoose,Graphql,Mongoose Schema,我在MongoDB中有以下字段,无法更改DB的模式 phoneNumbers: [ { phoneNumber: '15141234567', type: 'WORK' }, { phoneNumber: '15142233667', type: 'CELL' }, { phoneNumber: '1517654321', type: 'HOME' } ], 模式是 const schemaPhoneNumber = new Schema({ type: {
phoneNumbers: [
{ phoneNumber: '15141234567', type: 'WORK' },
{ phoneNumber: '15142233667', type: 'CELL' },
{ phoneNumber: '1517654321', type: 'HOME' }
],
模式是
const schemaPhoneNumber = new Schema({
type: {
type: String,
enum: ["WORK", "CELL", "HOME"],
alias: "phoneType", /////////////////////////////////// I have alias the field name
},
phoneNumber: String,
});
const GraphQLPhoneType = new GraphQLEnumType({
name: "PhoneType",
values: {
WORK: {
value: "WORK",
},
CELL: {
value: "CELL",
},
HOME: {
value: "HOME",
},
},
});
const GraphQLPhoneNumber = new GraphQLObjectType({
name: "PhoneNumber",
fields: () => ({
phoneType: { ////////////////////////////////////// it is not finding by this name
type: GraphQLNonNull(GraphQLPhoneType),
},
phoneNumber: {
type: GraphQLNonNull(GraphQLString),
},
}),
});
问题:当我运行查询时,它显示的是“电话号码”,但“电话类型”返回空值
如果我将“phoneType”更改为“type”,查询将显示正确的类型(工作、单元格等),但我必须在graphQL中使用“phoneType”,并且“type”是DB
当我使用别名进行更改时,问题是它在“GraphQLPhoneNumber”字段中不可用,这是嵌套JSON的问题还是我应该以不同的方式调用别名?别名是正确的,问题是我在创建上层架构时没有调用schemaPhoneNumber
phoneNumbers: [schemaPhoneNumber],