鍍金池/ 問(wèn)答/數(shù)據(jù)庫(kù)  HTML/ oplog update的疑問(wèn)

oplog update的疑問(wèn)

目前mongo3.6中新增了個(gè)ChangStream特性,可以很方便進(jìn)行增量數(shù)據(jù)撈取。但是在3.6版本之前就只能使用原始的oplog。而oplog的update操作記錄中有有大量$set修改器操作,在Change Data Capture時(shí)只能根據(jù)日志獲取到部分文檔。本人對(duì)mongo了解的不深,不知mongodb中oplog中有類(lèi)似mysql的binlog可以配置成ROW模式的選項(xiàng)嗎?而我想要的效果是在op:u操作時(shí)獲取到整個(gè)文檔的內(nèi)容。

回答
編輯回答
風(fēng)畔

oplog只會(huì)記錄變化的部分,沒(méi)有選項(xiàng)可以選擇不同的模式。Change stream是基于oplog的,所以其實(shí)它也只能給到變化的部分。Full Document模式給你的是經(jīng)過(guò)查詢(xún)之后得到的大多數(shù)節(jié)點(diǎn)上提交過(guò)的這個(gè)文件的版本。如果有其他操作夾在更新和這次讀取之間,你得到的可能會(huì)是后一次更新之后的文檔。這點(diǎn)在文檔里有描述:Look Full Document for Update Operations

If there are one or more majority-committed operations that modified the updated document after the update operation but before the lookup, the full document returned may differ significantly from the document at the time of the update operation.

不知道你的具體場(chǎng)景是什么,知道具體場(chǎng)景可能還可以進(jìn)一步探討其他解決方案。

2018年2月8日 01:55