我有以下文档结构:
"messages": {
"_id" : ObjectId("515a4de9c1a3c09c19000001"),
"author" : "50fd0d38c1a3c04c27000000",recipient" : "5159a292c1a3c01d5b000005",
"conversation" : [
{
"author" : "50fd0d38c1a3c04c27000000",
"date" : ISODate("2013-04-02T03:18:01.204Z"),
"message" : "hello test",
"read" : false
},
{
"message" : "reply test",
"date" : ISODate("2013-04-02T03:36:57.444Z"),
"author" : "5159a292c1a3c01d5b000005",
"read" : true
}....
是否可以获得会话消息的总数,其中 conversation.read 为 false 并且未读消息的作者(conversation.author)不是开始对话的人?
我目前正在查找将 conversations.read 设为 false 的文档,然后在 PHP 中循环它们以检查 conversations.author 字段。这行得通,但我担心当我获得大量数据时它会变慢。
我正在使用 PHP MongoDB 驱动程序。
这个我试过了。。
$unread_conversations = $db->messages->find(
array(
'conversation.read'=>false
'conversation.author'=>array('$ne'=>$_SESSION['account']['_id']->__toString())
));
但这不起作用,因为我想要未阅读且不是作者的消息。