NeDB データベースのデータを更新しようとするとField names cannot begin with the $ character
、DB を 2 回または 3 回更新した後にのみ発生します。
データの更新/挿入に使用しているコードは次のとおりです。
addNew: function(data) {
var deferred = $q.defer(),
query = {
_id: data._id,
title: data.title,
year: data.year,
genres: data.genres,
poster: data.poster
};
db.update(query, { $addToSet: { episodes: data.episodes[0] } }, { upsert: true }, function(err, numReplaced, upsert) {
if (!err) {
var data = numReplaced + '/' + upsert;
deferred.resolve(data);
} else {
deferred.reject(err);
}
});
return deferred.promise;
}
data.episodes[0]
次のようになります。
{
"number": 5,
"season": 3,
"title": "Kissed by Fire",
"overview": "The Hound is judged by the gods. Jaime is judged by men. Jon proves himself. Robb is betrayed. Tyrion learns the cost of weddings.",
"screen": "http://slurm.trakt.us/images/episodes/1395-3-5.80.jpg"
}
更新しようとしている DB のデータは次のようになります。
{
"_id": "tt0944947",
"title": "Game of Thrones",
"year": 2011,
"genres": "Drama, Fantasy, Adventure",
"poster": "http://slurm.trakt.us/images/posters/1395-300.jpg",
"episodes": [
{
"number": 10,
"season": 4,
"title": "The Children",
"overview": "Circumstances change after an unexpected arrival from north of the Wall. Daenerys must face harsh realities. Bran learns more about his destiny. Tyrion sees the truth about his situation.",
"screen": "http://slurm.trakt.us/images/episodes/1395-4-10.80.jpg"
}
]
}