Can’t get mongodb to populate information I am trying to push between collections

I am working on a mongodb project, I am trying to connect clients with their accounts. When I create a new account to go under the client, none of the information added shows up on the redirect page. Just blank spaces. When I look use a res.send(client), which I think would show both the new account and the related client I only get the account id's. I think this is the problem, but I am not sure how to populate the fields to push into clients.

Here's what I get:


This is the routing I am using (based on a course that seems to work fine for them(?)):'/clients/:id/accounts', async (req, res) => {
    const { id } = req.params;
    const client = await Client.findById(id);
    const { name, location, tid } = req.body;
    const account = new Account({ name, location, tid })
    account.client = client;
    // res.redirect(`/clients/${client._id}`)

Here are the two models I am working with: Clients:

   const mongoose = require('mongoose');
   const { Schema } = mongoose;

   const ClientSchema = new Schema({
   company: String,
   contact: String,
   phone: Number,
   email: String,
   city: String,
   state: String,
   zip: Number,
   accounts: [
        type: Schema.Types.ObjectId,
        ref: 'Account',

   module.exports = mongoose.model('Client', ClientSchema);

And the account model:

const mongoose = require('mongoose');
const { Schema } = mongoose;

const AccountSchema = new Schema({
    name: String,
    location: String,
    client: [{
        type: Schema.Types.ObjectId,
        ref: 'Client'
    description: String,
    contact: String,
    tid: String,
    loader: String,
    surcharge: Number,
    payout: Number,
    net: Number,

module.exports = mongoose.model('Account', AccountSchema);

Any help is greatly appreciated. Thanks in advance!!


Read more here:

Content Attribution

This content was originally published by SonofZappa at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: