小编san*_*osh的帖子

Mongodb数组$ push和$ pull

我想从数组中提取一些值并同时尝试更新它.

    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

mongodb

16
推荐指数
2
解决办法
9912
查看次数

使用nodeJS的MongoDB ensurIndex和createIndex?

我无法为以下内容创建索引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

indexing mongoose mongodb node.js

3
推荐指数
1
解决办法
4330
查看次数

基于Javascript的嵌套for循环和Objects

我是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)

javascript for-loop object nested-loops

-3
推荐指数
1
解决办法
81
查看次数