recherche

Maison  >  Questions et réponses  >  le corps du texte

mongodb 怎么设计已读内容不显示呢?

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

weibo: {type:String, default:null}

read: {type:objid,default: null}

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

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

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

为情所困为情所困2840 Il y a quelques jours756

répondre à tous(2)je répondrai

  • ringa_lee

    ringa_lee2017-04-28 09:06:43

    tableau thématique

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

    tableau des utilisateurs

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

    lire le tableau

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

    répondre
    0
  • 黄舟

    黄舟2017-04-28 09:06:43

    Lors de l'affichage, vérifiez simplement si la lecture est fausse

    répondre
    0
  • Annulerrépondre