Node.js 如何在同一Mongoose模式中将字符串与另一个键值连接起来
是否可以在同一Mongoose模式中连接字符串和前一个键值的值?下面的响应为未定义帐户Node.js 如何在同一Mongoose模式中将字符串与另一个键值连接起来,node.js,mongodb,mongoose,concatenation,Node.js,Mongodb,Mongoose,Concatenation,是否可以在同一Mongoose模式中连接字符串和前一个键值的值?下面的响应为未定义帐户 const mongoose = require("mongoose"); const Schema = mongoose.Schema; let TrackingSchema = new Schema({ account: { type: String, required: true, max: 100 }, accountURL: "https://www.instagram.com/"
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);
您可以创建一个:
TrackingSchema.virtual('accountURL').get(function(){
return "https://www.instagram.com/" + this.account;
});