fix: _openid为空时也应允许add()创建云端文档
之前当getOpenid未部署时,_doPush直接return,永远跳过了 db.collection().add(),导致集合无法自动创建、数据不能上云。 改为跳过locate+update但允许add(),CloudBase会自动填充_openid。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+5
-6
@@ -195,13 +195,12 @@ const _doPush = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} // else: openid is null — skip locate+update, go straight to add()
|
||||||
console.log('[cloud] _doPush no openid available, aborting (avoid duplicate add)')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reached only when we've positively confirmed no doc exists for our
|
// Reached when: (a) openid exists but no doc found, OR (b) openid is
|
||||||
// openid in the cloud — safe to add() the first document.
|
// null (getOpenid not deployed). In both cases add() is safe — CloudBase
|
||||||
|
// auto-populates _openid on document creation.
|
||||||
|
console.log('[cloud] _doPush adding new doc (openid=' + (openid || 'null') + ')')
|
||||||
const res = await db.collection(DB_COLLECTION).add({ data })
|
const res = await db.collection(DB_COLLECTION).add({ data })
|
||||||
if (res && res._id) _docId = res._id
|
if (res && res._id) _docId = res._id
|
||||||
if (res && res._openid) _openid = res._openid
|
if (res && res._openid) _openid = res._openid
|
||||||
|
|||||||
Reference in New Issue
Block a user