mongodb 怎么设计已读内容不显示呢?
为情所困
为情所困 2017-04-28 09:04:43
0
2
752

我有一个类似于微博的表, 功能是想让用户看过这条微博就不再显示了.

weibo: {type:String, default:null}

read: {type:objid,default: null}

然后循环对比吗? 实在想不通了 求救.

A 是消息表, B 是已读, C 是用户表.

A 表查询的时候 类似于 A._id != (B.read = true and C.uid = 1).readid

为情所困
为情所困

reply all(2)
左手右手慢动作

topic table

{
    "_id": ObjectId(12345) ,
    "title": "shajiquan.com"
}

user table

{
    "_id": ObjectId(112233445),
    "username": "shajiquan.com"
}

read table

{
    "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)

黄舟

When displaying, just check if read is false

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template