mongoDB

node js 에서 mongodb 필드추가

SeoHW 2021. 10. 19. 17:08
SMALL

var json = JSON.parse(JSON.stringify(req.query.p) //json 파라미터 req.query.p

 

var jp= eval("(" + req.query.p + ")") //파라미터로 받은 josn "{a: '22'}" 이런식으로 ""가 붙어있으므로 제거를위해 eval을 해준다  "{a: '22'}" -> {a: '22'} 이렇게된다

 

db.collection("컬렉션이름").updateMany({조건}, { $set : jp } , false , true ) 

.then(result =>{

         res.json({ result: 'ok' })

})

 

결과

 

a:22 

 

필드추가된걸확인할수있다.

LIST