2016-08-05 3 views
0

루프백 + mongoDB를 사용하여 API를 개발 중입니다. 그 나는 MongoDB의에서 문서의 배열을 업데이트 할 수 있습니다루프백 응용 프로그램을 통해 mongoDB의 배열을 업데이트하십시오.

내 모델 :

나는 데이터 전송 형태로 클라이언트와 새로운 요소와 배열 업데이트해야
{ 
    "userId": "546fgdfgd445", 
    "rrrr": "7", 
    "bbbbb": [ 
    {} 
    ], 
    "id": "57a437789521b58b12124016" 
} 

:

app.models.vvvvv.update({ userId: '546fgdfgd445' },{ $push: { "transactions": transactionData }}, function(err, res){ 
     if(err){ 
      console.log(err); 
     } else { 
      console.log(res); 
     } 
    }); 

하지만 오류가 발생합니다 :

{ name: 'MongoError', 
    message: 'The dollar ($) prefixed field \'$push\' in \'$push\' is not valid for storage.', 
    driver: true, 
    index: 0, 
    code: 52, 
    errmsg: 'The dollar ($) prefixed field \'$push\' in \'$push\' is not valid for storage.' } 

mongoDb 버전 3.2.3을 사용하고 있습니다.

아이디어를 공유하십시오. 미리 감사드립니다. model.json에서

+0

는'transactionData'는에 문제가있는 것 같다. – Shrabanee

+0

@Shrabanee No..its 완벽합니다 .. 그 대상, ... 배열 (\)에 객체 ({})를 밀어 넣으려고합니다. \ – Subburaj

+0

몽고 껍질에서 직접이 작업을 시도해 볼 수 있습니까? 나는 당신이 쓴 방식대로 해봤고 잘 작동합니다. – Shrabanee

답변

0

는이 같은 확장 된 작업을 사용하도록 설정해야합니다 :

"options": {  
    "mongodb": { 
     "collection": "model_collection", 
     "allowExtendedOperators": true 
    } 
    }, 

또는

무엇
app.models.vvvvv.update({ userId: '546fgdfgd445' }, 
{ $push: { "transactions": transactionData }}, { allowExtendedOperators: true }, function(err, res){ 
      if(err){ 
       console.log(err); 
      } else { 
       console.log(res); 
      } 
     }); 
관련 문제