我想从数组中提取一些值并同时尝试更新它.
userSchema.statics.experience = function (id,xper,delet,callback) {
var update = {
$pull:{
'profile.experience' : delet
},
$push: {
'profile.experience': xper
}
};
this.findByIdAndUpdate(id,update,{ 'new': true},function(err,doc) {
if (err) {
callback(err);
} else if(doc){
callback(null,doc);
}
});
};
Run Code Online (Sandbox Code Playgroud)
我得到的错误就像 MongoError: exception: Cannot update 'profile.experience' and 'profile.experience' at the same time
我无法为以下内容创建索引profile:
var user = new Schema({
profile : "String",
fullname:"String"
})
user.statics.createIndexOfProfile = function(callback){
this.ensureIndex("profile",function(err,doc){
if(err) {
console.log(err+'sna');
callback(err);
}
else {
console.log(doc+'santhosh');
callback(null,doc);
}
});
Run Code Online (Sandbox Code Playgroud)
我得到的错误就像 this.ensureIndex is not a function
我是javascript的新手.当我使用对象和嵌套循环时.有弹药可供选择
var a = [{b:[{c:null}]}]
for(var x= 0 ; x<10;x++){
for(var y= 0 ; y<10;y++){
console.log(a);
a[x].b[y].c = y;
console.log(a);
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误就像TypeError: Cannot set property 'c' of undefined有人可以解释为什么它这样工作.我本来想要这样
a[0].b[0].c = 1;
a[0].b[1].c = 2;......
a[1].b[0].c = 1;....
a[9].b[9].c = 9;
Run Code Online (Sandbox Code Playgroud) mongodb ×2
for-loop ×1
indexing ×1
javascript ×1
mongoose ×1
nested-loops ×1
node.js ×1
object ×1