我是新的rethinkdb,我想寫一個更新查詢首選upsert它將設置值爲幾個字段,如果他們不存在或他們的值小於我想要的新值設置。下面是我的MongoDB所採取的方式Conditinal更新的幾個字段
collection.updateOne(new BasicDBObject(BookKeeperEvent.tenantPropertyName, bookKeeper.getTenantId()).append(BookKeeperEvent.timeLayerPropertyName, bookKeeper.getTimeLayer()),
new BasicDBObject("$max", new BasicDBObject(BookKeeperEvent.latestFullDataPropertyName, bookKeeper.getLatestFullData())
.append(BookKeeperEvent.latestRawDataPropertyName, bookKeeper.getLatestRawData())
.append(BookKeeperEvent.latestHealthPropertyName, bookKeeper.getLatestHealth())
.append(BookKeeperEvent.lastUpdatePropertyName, bookKeeper.getLastUpdate())
.append(BookKeeperEvent.firstFullDataPropertyName, bookKeeper.getFirstFullData()))
.append("$setOnInsert", new BasicDBObject(BookKeeperEvent.tenantPropertyName, bookKeeper.getTenantId()).append(BookKeeperEvent.timeLayerPropertyName, bookKeeper.getTimeLayer())),
new UpdateOptions().upsert(true))
此代碼設置tenantId和timeLayer只有當他們是空的,而對於其他領域,只有當他們都爲空或值小於我在設置的值查詢。 有沒有辦法在rethinkdb中做同樣的事情?如何?
感謝, 丹妮拉
我覺得下面的查詢就相當於我在蒙戈沒有,但它失敗。 – Daniela