2011-11-08 4 views
1

몽구스로 내 mongoDB에 작업을 처리하면 성공이 처리되고 내 문서는 저장되지만 다른 종류의 다른 sutff도 적어집니다. 그것은 몽구스 코드 인 것 같습니다. 무엇이 이것을 일으킬 수 있습니까?몽구스로 mongoDb에 저장, 예기치 않은 요소가 저장된

난으로 특정 배열에 재료를 추가

resultReference.ref[arrayLocation].allEvents.push(theEvent); 

{ID : 11 allEvents []}의 Ref 소자의 구조이고, I는 allEvents 배열 theEvent 밀어. 그 때 resultReference.save()

나는 express, mongoose 및 mongoHQ를 데이터베이스로 사용합니다. 나는 지역의 mongo 서버를 시험해 보았다. 그리고이 성가심은 아직도 거기에있다. 내 콘솔에 save() 전에 쓰려고하는 문서를 출력했고이 이상한 코드는 존재하지 않습니다.

{ 
id 11 
allEvents 
[ 
0 
{ 
_events 
{ 
maxListeners 0 
} 
_doc  
{ 
_id {"$oid": "4eb87834f54944e263000003"} 
title "Test" 
allDay false 
start 2011-11-10 13:00:00 UTC 
end 2011-11-10 15:00:00 UTC 
url "/test/4eb87834f54944e263000002" 
color "#99CCFF" 
ref "4eb87834f54944e263000002" 
} 
_activePaths  
{ 
paths 
{ 
title "modify" 
allDay "modify" 
start "modify" 
end "modify" 
url "modify" 
color "modify" 
ref "modify" 
} 
states 
{ 
init  
{ } 
modify 
{ 
title true 
allDay true 
start true 
end true 
url true 
color true 
ref true 
} 
require 
{ } 
} 
stateNames 
[ 
0 "require" 
1 "modify" 
2 "init" 
] 
} 
_saveError null 
_validationError null 
isNew true 
_pres 
{ 
save  
[ 
0 
function (next) { 
    // we keep the error semaphore to make sure we don't 
    // call `save` unnecessarily (we only need 1 error) 
    var subdocs = 0 
     , error = false 
     , self = this; 

    var arrays = this._activePaths 
    .map('init', 'modify', function (i) { 
     return self.getValue(i); 
    }) 
    .filter(function (val) { 
     return (val && val instanceof DocumentArray && val.length); 
    }); 

    if (!arrays.length) 
     return next(); 

    arrays.forEach(function (array) { 
     subdocs += array.length; 
     array.forEach(function (value) { 
     if (!error) 
      value.save(function (err) { 
      if (!error) { 
       if (err) { 
       error = true; 
       next(err); 
       } else 
       --subdocs || next(); 
      } 
      }); 
     }); 
    }); 
    } 
1 "function checkForExistingErrors(next) { 
if (self._saveError){ 
next(self._saveError); 
self._saveError = null; 
} else { 
next(); 
} 
}" 
2 "function validation(next) { 
return self.validate.call(self, next); 
}" 
] 
} 
_posts 
{ 
save  
[ ] 
} 
save  
function() { 
     var self = this 
     , hookArgs // arguments eventually passed to the hook - are mutable 
     , lastArg = arguments[arguments.length-1] 
     , pres = this._pres[name] 
     , posts = this._posts[name] 
     , _total = pres.length 
     , _current = -1 
     , _asyncsLeft = proto[name].numAsyncPres 
     , _next = function() { 
      if (arguments[0] instanceof Error) { 
       return handleError(arguments[0]); 
      } 
      var _args = Array.prototype.slice.call(arguments) 
       , currPre 
       , preArgs; 
      if (_args.length && !(arguments[0] === null && typeof lastArg === 'function')) 
       hookArgs = _args; 
      if (++_current < _total) { 
       currPre = pres[_current] 
       if (currPre.isAsync && currPre.length < 2) 
       throw new Error("Your pre must have next and done arguments -- e.g., function (next, done, ...)"); 
       if (currPre.length < 1) 
       throw new Error("Your pre must have a next argument -- e.g., function (next, ...)"); 
       preArgs = (currPre.isAsync 
          ? [once(_next), once(_asyncsDone)] 
          : [once(_next)]).concat(hookArgs); 
       return currPre.apply(self, preArgs); 
      } else if (!proto[name].numAsyncPres) { 
       return _done.apply(self, hookArgs); 
      } 
      } 
     , _done = function() { 
      var args_ = Array.prototype.slice.call(arguments) 
       , ret, total_, current_, next_, done_, postArgs; 
      if (_current === _total) { 
       ret = fn.apply(self, args_); 
       total_ = posts.length; 
       current_ = -1; 
       next_ = function() { 
       if (arguments[0] instanceof Error) { 
        return handleError(arguments[0]); 
       } 
       var args_ = Array.prototype.slice.call(arguments, 1) 
        , currPost 
        , postArgs; 
       if (args_.length) hookArgs = args_; 
       if (++current_ < total_) { 
        currPost = posts[current_] 
        if (currPost.length < 1) 
        throw new Error("Your post must have a next argument -- e.g., function (next, ...)"); 
        postArgs = [once(next_)].concat(hookArgs); 
        return currPost.apply(self, postArgs); 
       } 
       }; 
       if (total_) return next_(); 
       return ret; 
      } 
      }; 
     if (_asyncsLeft) { 
     function _asyncsDone (err) { 
      if (err && err instanceof Error) { 
      return handleError(err); 
      } 
      --_asyncsLeft || _done.apply(self, hookArgs); 
     } 
     } 
     function handleError (err) { 
     if ('function' == typeof lastArg) 
      return lastArg(err); 
     if (errorCb) return errorCb.call(self, err); 
     throw err; 
     } 
     return _next.apply(this, arguments); 
    } 
errors null 
} 
] 
} 
] 

답변

1

이유는 내가 올바른 스키마에 몽구스로 스키마를 저장하지 않았기 때문입니다. 이는 부모가 적절한 행동을 취하기 전에 자녀의 스키마를 선언하는 것을 의미합니다.