我有一个集合,我的集合的一部分在这里,
让我们调用第一个数组
$ho = array( 'a' =>
array (
'0' => '508bef9e6803fa6305000000',
'1' => '50901eac6803fafb0d000000',
'2' => '508bf3766803fa810f000000',
'3' => '50a2aeac6803fa150b000000',
'4' => '50a2ae846803fa140b000000',
'5' => '50a2ae616803fab706000000',
'6' => '50a2ae3a6803fab506000000',
'7' => '50a2adfc6803fab306000000',
)),
并且还有另一个来自其他用户的嵌入数组,让我们调用第二个数组
'_id' => new MongoId("508bef9e6803fa6305000000"),
'a' =>
array (
'0' => '508bf3766803fa810f000000',
'1' => '50a2ae616803fab706000000',
'2' => '50a2aeac6803fa150b000000',
),
我想要做的是从第一个数组中减去第二个数组,但我想用mongodb做它
'a' =>
array (
'0' => '508bef9e6803fa6305000000',
'1' => '50901eac6803fafb0d000000',
'4' => '50a2ae846803fa140b000000',
'6' => '50a2ae3a6803fab506000000',
'7' => '50a2adfc6803fab306000000',
),
我尝试了不同的查询,但无法得到像这样的结果,谢谢你的任何帮助:)
$lk = $m->kud->user->findOne(
array(
"_id" => new MongoId("508bef9e6803fa6305000000"),'$nin'=>array("a"=>$ho["a"])
),
array("_id" => 0, "a" => 1)
);
答案 0 :(得分:0)
MongoDB目前不支持基于值匹配的投影(最终会)。对于这样的情况,您可能需要返回整个文档,然后拉出客户端的值。