我的架构是
var User = new mongoose.Schema({
//general information
name : {type:String},
email : {type : String},
number : {type : String},
password : {type:String},
//featured information
path: { type: String},
dob : {type:String},
gender : {type : String},
blood_group : {type:String},
marital_status : {type : String}
});
module.exports = mongoose.model('user',User);
我想通过 -
更新一些细节app.post('/contactinfo',function (req,res) {
var name = req.body.name;
var number = req.body.number;
var email = req.body.email;
User.update({_id : userID},{
$push : {
name : name,
number : number,
email : email
}
},{new : true },function (err,result) {
if(err){
console.log(err);
}
else{
console.log(result);
res.send({status : "success" , message : "Details updates"});
}
});
});
我没有在任何地方定义数组
但问题是更新时显示错误
{ MongoError: The field 'name' must be an array but is of type string in document {_id: ObjectId('5a0880e2d767e8131807e7f4')}
我被困在这里
请有人帮我解决此错误
答案 0 :(得分:1)
您只需将vector<int> buildKMPtable(string word)
{
vector<int> kmp(word.size());
int j=0;
for(int i=1; i < word.size(); ++i)
{
j = word[j] == word[i] ? j : kmp[j-1];
if(word[j] == word[i])
{
kmp[i] = j + 1;
++j;
}
else
{
kmp[i] = j;
}
}
return kmp;
}
bool repeatedSubstringPattern(string s) {
auto kmp = buildKMPtable(s);
if(kmp[s.size() -1] == 0) // Occurs when the string has no prefix with suffix ending at the last character of the string
{
return false;
}
int diff = s.size() - kmp[s.size() -1]; //Length of the repetitive pattern
if(s.size() % diff != 0) //Length of repetitive pattern must be a multiple of the size of the string
{
return false;
}
// Check if that repetitive pattern is the only repetitive pattern.
string word = s.substr(0, diff);
int w_size = word.size();
for(int i=0; i < w_size; ++i)
{
int j = i;
while(j < s.size())
{
if(word[i] == s[j])
{
j += w_size;
}
else
{
return false;
}
}
}
return true;
}
更改为$push
即可。那就是它。