내 컬렉션에는 문서가 하나뿐입니다.
> db.c20160712.find()
{ "_id" : ObjectId("57ab909791c3b3a393e9e277"), "Dimension_id" : 2, "Attribute" : "good", "Hour" : "20160712_06", "Frequency_count" : 100
updateOne
문서를 다른 문서로 교체 하기 위해 실행하고 싶습니다 . 하지만 왜 거기에 Error: the update operation document must contain atomic operators
있습니까?
> db.c20160712.updateOne( { "Attribute" : "good"}, {"Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action"}, { upsert: true} )
2016-08-10T16:37:57.089-0400 E QUERY [thread1] Error: the update operation document must contain atomic operators :
DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:493:1
@(shell):1:1
위 명령의 두 번째 및 세 번째 인수는 The Definitive Guide to MongoDB : A complete guide to handling BigData … 작성자 : Eelco Plugge, David Hows, Peter Membrey, Tim Hawkins
내 MongoDB는 3.2입니다.
답변
답변
나는 이것이 도입의 부작용으로 변경되었다고 생각합니다. updateOne()
이외에 방법 update()
과 updateMany()
같이 다소 보호의 실수 전체 문서에서 사용자의 재정을 방지 할 수있다.
replaceOne()
대신 메서드를 사용하거나 update()
를 지정하지 않고 사용할 수 있습니다 multi:true
.
답변
이 코드를 사용해야하는 이유는 동일한 문제에 직면했고 다음 코드를 사용했기 때문입니다.
updateOne(
{ _id: new ObjectID(req.params.id) },
{ $set: { title: req.body.bookName, author: req.body.authorName } },
{ upsert: true }
)
ObjectID
그렇지 않으면 문제가 다시 발생 한다는 것을 정의해야 합니다.
const ObjectID = require('mongodb').ObjectID;
답변
당신은 저와 같은 실수를 저질렀습니다. 문서를 살펴보면서 구문이 잘못되었음을 깨달았습니다. 시험:
db.c20160712.updateOne(
{ "Attribute" : "good"},
{"Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action"},
{ upsert: true}
)