2014-01-24 2 views
0

을 설정합니다. 문자열을 통해서도이 작업을 수행 할 수 있습니다. 그래서 SET 절은 다음과 같습니다mongojs 표기법이이 mongojs 객체가 업데이트 될 때 어떻게

  $set: 
     { 
     'comment': "Hello", 
     }, 

내 요점은 : 나는

   var type = "external_property" 

을 할 수있는 dnymaic 속성을 만들려하지만 속성 유형을 추가 할 때 할당됩니다. 그러나 type은 'external_comment'를 제공하는 문자열로 읽어야합니다.

어떻게하면됩니까?

답변

0

이 시도 :

var dynamic_property = 'my_dynamic_property', // or whatever you want 
    update = { 
     $set: {} 
    }; 

update.$set[dynamic_property] = 'Hello'; 

db.books.update({_id:tg._id}, update, ...);