Pouchdb。如何验证文档是否已复制 [英] Pouchdb. How to verify a doc is replicated

查看:66
本文介绍了Pouchdb。如何验证文档是否已复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上是使用poychdb来让移动用户离线创建销售订单,然后将它们复制到中央Couchdb服务器,然后在Cron作业的基础上在那里处理它们。

Im using poychdb basically to let a mobile user create sales orders offline, then later replicate them to central couchdb server, then process them there on a cron job basis.

由于复制可以同步某些文档...然后停止(丢失Internet ...),我需要一种方法来阻止移动用户编辑那些已同步的订单。但是hd仍然可以编辑其他尚未上传的订单

As replication can sync some docs...then stop (lost Internet. ..) i need a way to block the mobile user from editing those already synced orders. But hd can still edit other non-yet-uploaded orders

有某种方法吗?

推荐答案

replicate()函数返回一个事件发射器,该事件发射器发出'change'事件: http://pouchdb.com/api.html#replication

The replicate() function returns an event emitter which emits a 'change' event: http://pouchdb.com/api.html#replication.

因此您可以收听'change'事件,该事件将告诉您写入了多少文档以及 seq (更新序列号)。使用更改feed和 since 参数,您可以确定哪些文档已被写入远程数据库。

So you can listen for 'change' events, which will tell you how many documents were written and the seq (update sequence #) of the last written document. Using the changes feed and the since parameter, you can figure out which documents were already written to the remote database.

例如如果 last_seq 是50,则 changes({since:50})将为您提供所有未已同步。

E.g. if the last_seq is 50, then changes({since: 50}) will give you all documents that haven't been synced yet.

这篇关于Pouchdb。如何验证文档是否已复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆