Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在同一Mongoose模式中将字符串与另一个键值连接起来_Node.js_Mongodb_Mongoose_Concatenation - Fatal编程技术网

Node.js 如何在同一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/"

是否可以在同一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/" + 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;
});