我有一个类似于微博的表, 功能是想让用户看过这条微博就不再显示了.
weibo: {type:String, default:null}
read: {type:objid,default: null}
然后循环对比吗? 实在想不通了 求救.
A 是消息表, B 是已读, C 是用户表.
A 表查询的时候 类似于 A._id != (B.read = true and C.uid = 1).readid
ringa_lee2017-04-28 09:06:43
{
"_id": ObjectId(12345) ,
"title": "shajiquan.com"
}
{
"_id": ObjectId(112233445),
"username": "shajiquan.com"
}
{
"user_id": ObjectId(12345),
"topic_id": ObjectId(67890)
}
# 某用户 阅读过的
has_read = db.read.find({'user_id':USER_ID},{'topic_id':1})
has_read = [i.get('topic_id') for i in list(has_reads)]
# 某用户 没有阅读过的
topics = db.topics.find({'topic_id':{'$nin':has_read}})
topics = list(topics)