2

Is it possible to concatenate a string and a value of a previous key value in the same Mongoose schema? The below responds with account is not defined

const mongoose = require("mongoose");
const Schema = mongoose.Schema;

let TrackingSchema = new Schema({
    account: { type: String, required: true, max: 100 },
    accountURL: "https://www.instagram.com/" + account,
    followedBack: { type: Number, required: true }
},
{
    timestamps: true
});

// Export the model
module.exports = mongoose.model("Tracking", TrackingSchema);

1 Answer 1

1

You can create a virtual property:

TrackingSchema.virtual('accountURL').get(function(){
    return "https://www.instagram.com/" + this.account;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.