现在我正在使用clmtrackr库来检测来自网络摄像头的情绪,我想保存这种情绪这是我的node.js代码,用于保存mongodb中的值
exports.storeemotion = function (emotions, callback){
var eshema= new emotioncollection({
emotions: [emotions]
});
eshema.save(function(err) {
});
callback({"status":"emotion remote done"});
}
,架构代码为
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//var bcrypt = require('bcrypt-nodejs');
// search results schema
var ResultaSchema = new Schema({
emotions:[{emotion: String, value: String}]
});
module.exports = mongoose.model('emotioncollection',ResultaSchema);
情绪应该是那样的(check this image)。
但是mongo保存了一个空数组(check this image)。
答案 0 :(得分:0)
emotions
函数的storeemotion
参数已经是一个数组,所以你只需按原样传递参数,而不是另一个数组:
exports.storeemotion = function (emotions, callback) {
var eshema = new emotioncollection({
emotions: emotions // <= your schema already expects an array of objects
});
eshema.save(function(err) {
if (err) return callback({"status": "error"});
callback({"status": "emotion remote done"});
});
}