在处理 Mongo 文档中的嵌套数组时,无论是插入、删除还是更新,都会用到 db.collection.update()
我遇到的问题是 v3.6+ 中的新更改流。
我需要一种方法来区分来自于的更改事件中的这些操作 collection.watch()
例子:
使用文档架构:
{
id: string,
array: [{id: string, value: string}]
}
Run Code Online (Sandbox Code Playgroud)
插入嵌套数组:
collection.updateOne(
{id: 'some_id'},
{$push: {'array.$': {id: 'nested_id', value: 'new nested item'} } }
)
Run Code Online (Sandbox Code Playgroud)
更改流将响应:
{
...
operationType: 'update',
updateDescription: {
updatedFields: 'array.0': {id: 'nested_id', value: 'new nested item'}
... }
}
Run Code Online (Sandbox Code Playgroud)
更新嵌套数组项:
collection.updateOne(
{id: 'some_id', 'array.id': 'nested_id'},
{$set: {'array.$.name': 'new nested name' } }
)
Run Code Online (Sandbox Code Playgroud)
更改流将响应:
{
...
operationType: 'update',
updateDescription: {
updatedFields: 'array.0.name': 'new nested …Run Code Online (Sandbox Code Playgroud) a: 1---2-3-4--5---6
b: ------T---------
o: ------1234-5---6
Run Code Online (Sandbox Code Playgroud)
使用RxJS,是否有一些运算符可以完成上图?我有一个流 A,它是一个随机事件流,给定一个具有单个true事件的流 B,我可以有一个输出流,在该事件之前不发出任何内容true,然后发送在此之前和之后保存的所有内容正常发射?
我想也许我可以使用buffer(),但似乎没有办法用该运算符进行像这样的一次性缓冲区。