B
B
bogdansunsets2020-08-27 09:49:03
JavaScript
bogdansunsets, 2020-08-27 09:49:03

Information from mongodb not outputting to pug element?

There is a Biography key in the database schema, and we need to display it in the modal window of the PUG document. Nothing is output in PUG.
scheme:

const characterSchema = new Schema({
    desc: String,
    tag: String,
    info: String,
    creator: String,
    state: Object,
    account: {
        type: Schema.Types.ObjectId,
        index: true,
        ref: 'Account'
    },
    site: {
        type: Schema.Types.ObjectId,
        ref: 'Auth'
    },
    name: {
        type: String,
        index: true
    },
    flags: {
        type: Number,
        default: 0
    },
    lastUsed: {
        type: Date,
        index: true
    },
    biography: {
        type: String,
        index: true
    },
}, { timestamps: true });


Here is the schema model:
export const Character = model<ICharacter>('Character', characterSchema);


User id query function:
export async function exportBiography(res:any, accountId: ID){
    const modalb = await Character.findById(accountId); 
    res.render('index', { modalb: JSON.stringify(modalb) });
}


Calling a function in a switch construct (fragment):
case PlayerAction.ShowModal:
                app.get(this.client.accountId, (req: any, res: any) => {
                    exportBiography(res, req.parrams.id);
                  });


Directly a modal window in PUG, where we need to display our key (an attempt to display the necessary data in .modal-content):
.modal-overlay
                .modal
                    a.close-modal
                      svg(viewbox='0 0 20 20')
                        path()
                        // close modal
                    .modal-content
                        | {{modalb.biography}}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
ylfa, 2020-08-27
@ylfa

const modalb = await Character.findById(accountId).exec();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question