当尝试更新 NeDB 数据库中的数据时,我得到了Field names cannot begin with the $ character
但是它只发生在第二次或第三次更新数据库之后。
这是我用来更新/插入数据的代码:
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"
}
我尝试更新的数据库中的数据如下所示:
{
"_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"
}
]
}