首先,这段代码从今天开始完美运行,我不知道为什么,这已经改变了,我没有修改它。这是代码:
app.post('/upload', function (req, res){
var tags = req.body.tags.split(" ");
usermodel.findOne({ user: req.session.user }, function (err, user){
console.log(user);
var img = user.imagen.push({
title: req.body.title,
name: req.files.art.name,
author: user.user,
description: req.body.description,
index: user.imagen.length + 1,
path: './users/' + user.user + '/' + req.files.art.name,
dowload: req.body.share,
tags: tags
});
user.save(function (err, suser){
if (err) throw err;
fs.readFile(req.files.art.path, function(err, data){
if (err) throw err;
fs.writeFile(user.path + '/' + req.files.art.name, data, function(err){
if(err) throw err;
res.redirect('/home');
});
});
});
});
当我检查一个用户时,该用户的 imagen 数组看起来像这个'[object Object]'。为什么会发生这种情况?对此有什么解决方案...?
谢谢提前!
编辑:
这是架构:
var usersschema = new mongoose.Schema({
user: String,
pass: String,
imagen: [{
title: String,
name: String,
views: Number,
type: String,
author: String,
tags: [String],
description: String,
index: Number,
path: String,
date: { type: Date, default: Date.now },
dowload: String,
like: Number,
}],
});