android - 无效的查询。您不能将“array_contains”过滤器与“not_in”过滤器一起使用
问题描述
我有一个名为频道的集合。
用户被添加到userIds数组中,记录也被保存到名为serverId的字段中。
我只需要一个新创建或更新的行列表来更新到我的本地房间数据库。
每次发生任何更改时,我都会更新snapshotTime字段。
以前我使用以下代码,其中lastTime 是本地房间 db 的 max(snapshotTime)
FirestoreUtil.chatChannelCollectionRef
.whereArrayContains("userIds", currentUserId)
//.whereGreaterThan("snapshotTime", lastTime)
.orderBy("snapshotTime", Query.Direction.ASCENDING)
.startAfter(lastTime)
.addSnapshotListener (activity) { snapshots, e ->
if (e != null) {
Log.e("exception occurred", "")
return@addSnapshotListener
}
for (dc in snapshots!!.documentChanges) {
when (dc.type) {
DocumentChange.Type.ADDED -> {
val chatChannel = dc.document.toObject(ChatChannel::class.java)
chatChannel.serverId = dc.document.id
repository.insertOrUpdateChannel(channelDao, chatChannel)
Log.e(TAG, "ADDED chatChannel: ${dc.document.data} - ${dc.document.id}")
}
DocumentChange.Type.MODIFIED -> {
val chatChannel = dc.document.toObject(ChatChannel::class.java)
chatChannel.serverId = dc.document.id
repository.insertOrUpdateChannel(channelDao, chatChannel)
Log.e(TAG, "MODIFIED chatChannel: ${dc.document.data} - ${dc.document.id}")
}
DocumentChange.Type.REMOVED -> {
val chatChannel = dc.document.toObject(ChatChannel::class.java)
chatChannel.serverId = dc.document.id
//MessageDatabase.getDatabase(AjoowebApplication.applicationContext()).runInTransaction {
repository.deleteChannel(channelDao, chatChannel)
Log.e(TAG, "REMOVED chatChannel: ${dc.document.data} - ${dc.document.id}")
}
else -> {
Log.e(TAG, "MISSING: ${dc.document.data} - ${dc.document.id}")
}
}
}
}
它返回更新的字段,但不返回新记录。
所以我尝试了这个查询来只获取新行:
这里的 channels 是一个列表,其中包含本地数据库中的所有 channelsId
FirestoreUtil.firestoreInstance
.collection(FBCollections.CHANNEL_COL)
.whereNotIn("serverId", channels)
.whereArrayContains("userIds", currentUserId)
.get()
.addOnSuccessListener (activity) { snapshots ->
for (dc in snapshots!!.documents) {
val chatChannel = dc.toObject(ChatChannel::class.java)!!
chatChannel.serverId = dc.id
repository.insertOrUpdateChannel(channelDao, chatChannel)
Log.e(TAG, "LOADED chatChannel: ${dc.data} - ${dc.id}")
}
}
现在遇到的错误是:
无效的查询。您不能将“array_contains”过滤器与“not_in”过滤器一起使用
我怎样才能得到新创建的记录呢?
解决方案
推荐阅读
- python - 在python的类函数中更改全局变量
- python - GroupBy Pandas 连续计数零
- python - Matplotlib imshow() 给出一个水平翻转的密度图
- c# - c# Bootstrap 在转发器中使用 if else for eval()
- javascript - 如何在 D3 条形图中添加分隔符
- jmeter - Jmeter - 找出 HTTP 样本何时开始占用高响应时间
- python - 如何使用 python 子进程 Popen 调用通过 SSH 连接到远程服务器来执行 awk 命令?
- javafx - 如何在 JavaFX 中全屏制作有关 jxbrowser 的嵌入式 Youtube 视频
- django - Django ForeignKey 数据分组
- javascript - 在为所有浏览器加载 pdf 时禁用 iframe 上的上下文菜单?