0
當試圖更新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"
}
中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"
}
]
}
看看這個https://github.com/louischatriot/nedb/issues/229 – GPrathap 2015-01-15 02:03:45
@ user1574779我很感謝你試圖幫忙(在這個問題中3個月的沉默之後,我甚至忘了它在這裏哈哈) ,但我沒有在我的代碼中使用位置運算符。 我相信這是一個錯誤,但恐怕我無法檢查,因爲我停止開發這個問題的應用對象,現在可能有一個新版本的NeDB。再次查看代碼,這可能是導致問題的「upsert」,我不確定是否檢查了該問題。 – 2015-01-16 02:36:33