0
嵌套文檔的自定義ID這是不行的,但希望這和標題滿口得到跨越條件UPSERT基於流星
function addToDB(account_id)
{
obj = {};
if (!Accounts.findOne({account_id: account_id})) obj.createdAt = new Date().valueOf();
obj.account_id = account_id;
Accounts.upsert({account_id: account_id}, {$set: obj});
}
我需要使用ACCOUNT_ID代替的MongoDB點對象ID,所以它必須是可索引/唯一的。如果是更新,createdAt不應該改變。
更新,以便它工作在原有的範圍內,但我更喜歡我正確的答案評論的解決方案。
,似乎工作。 :)'accounts.upsert({account_id:account_id},{$ setOnInsert:{'createdAt':new Date()。valueOf()},$ set:obj});'' – jiku 2014-09-13 04:17:11