search

Home  >  Q&A  >  body text

mongodb 文档数组查询的一个问题

1对多群发消息,文档结构如下:

{
"from_uid" : 10000,
"to_uid" :
[

{ "user_id" : 100002, "is_read" : 1, "is_del" : 1 }, 
{ "user_id" : 100003, "is_read" : 0, "is_del" : 0 }, 
{ "user_id" : 100004, "is_read" : 1, "is_del" : 0 } 

]
}

其中to_uid.user_id=100002,设置为is_del=1。执行以下指令的时候,这个文档还会显示。 貌似查询条件里的"to_uid.user_id" "to_uid.is_del" 是或的关系?

db.notice.find({"to_uid.user_id":100002, "to_uid.is_del":0 , "create_time":8})

滿天的星座滿天的星座2793 days ago818

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-04-27 09:04:45

    db.notice.find({"to_uid":{$elemMatch:{"user_id":100002,"is_del":0}}"create_time":8})

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-27 09:04:45

    I encountered the same problem, and I always thought it was or , not &&,
    I wonder if the author has solved it?

    reply
    0
  • Cancelreply