I have the following data in a MongoDB.
{
"experiences": {
"Project0": [{
"title": "AA"
},
{
"title": "BB",
"sub": "B"
},
{
"title": "CC",
"sub": "C"
}
],
"Project1": [
{
"title": "AA",
"sub": "A"
}
]
}
}
I want to get Project0 and Project1 back from a GraphQL query. My current mongoose.Schema only retrieves data for “Project0”.
Book.js
import mongoose from "mongoose";
const pastProjectsSchema = new mongoose.Schema({
experiences:{
Project0:[
{
title: String,
sub: String
}
]
}
})
export const Experience = mongoose.model( "Experience", pastProjectsSchema , "experiences");
typeDefs.js
import gql from 'graphql-tag';
export const typeDefs = gql`
type Query {
experiences: [Experiences]
}
type Experiences{
experiences:Experience
}
type Experience {
Project0: [ProjectDetail]
}
type ProjectDetail {
title: String
sub: String
}
`;
resolvers.js
import { Experience} from './models/Book.js'
export const resolvers = {
Query: {
experiences: async() => await Experience.find({}),
}
};