You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can update the m metadata field in middleware, like so:
backend.use('connect',(request,callback)=>{// request.agent.custom is a place for holding arbitrary data you attach// from the connection. It's available in all other middleware.// request.req comes from the second argument of backend.listen (see below)request.agent.custom=request.req;});backend.use('submit',(request,callback)=>{// We can just attach the metadata from our agent.custom object to the// op.m metadata fieldrequest.op.m.userId=request.agent.custom.userId;});// Pass user information in when establishing their connection. This will come from// a cookie or database, or whatever auth mechanism you've usedbackend.listen(stream,{userId: '123'});// Fetch ops from v5 (inclusive) to v10 (non-inclusive), along with the metadata,// which includes the custom userId we set:backend.getOps(agent,'collection','id',5,10,{opsOptions: {metadata: true}},(error,ops)=>{// ops has the metadata attached to each op});
Yes unfortunately the fetchSnapshot doesn't currently support any options (and hence can't send back metadata). You'll need to make a separate (server-side) call to backend.getOps (as outlined above), or we're more than happy to accept a Pull Request that adds this functionality!
Activity
alecgibson commentedon Dec 7, 2020  
You can update the
mmetadata field in middleware, like so:aeroyu commentedon Dec 8, 2020  
req can pass in client submitOp method,in my case i need to related the op version and the user
alecgibson commentedon Dec 8, 2020  
The op version is already stored on the op, which you'll have access to on the
requestobject.aeroyu commentedon Dec 8, 2020  
any example? thx,how can i stored userId to op
alecgibson commentedon Dec 8, 2020  
I just gave you an example above.
aeroyu commentedon Dec 8, 2020  
i get the example from #224 and slove it
but another question is , i use client api fetchSnapshot and the result m is null
alecgibson commentedon Dec 8, 2020  
Yes unfortunately the
fetchSnapshotdoesn't currently support any options (and hence can't send back metadata). You'll need to make a separate (server-side) call tobackend.getOps(as outlined above), or we're more than happy to accept a Pull Request that adds this functionality!aeroyu commentedon Dec 8, 2020  
:》
nieyuyao commentedon Dec 22, 2020  
How can I add custom filed when submit op at client side? The methods mentioned above are all completed on the server side?:)
alecgibson commentedon Dec 23, 2020  
@nieyuyao can you please provide a use-case example?
nieyuyao commentedon Dec 24, 2020  
Oh, my bad. I misunderstand!Thanks :)
listar commentedon Apr 28, 2022  
client 的 sendOp函数源代码如下:
客户端 doc.submitSource = true
在source内补充你想要补充的数据