Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用MongoDB和PHP的手动引用_Php_Mongodb - Fatal编程技术网

使用MongoDB和PHP的手动引用

使用MongoDB和PHP的手动引用,php,mongodb,Php,Mongodb,我有两个收藏: “用户”集合 _id: ObjectID('56c9a824f4b233dfd30041b3') name: Luke Skywalker username: jedimaster23 及 “projectInfo”集合 _id: 56d1d830f4b233ded30041c3 projectName: L startDate: 24 April 2016 users_id: ObjectID('56c0abb7f4b233ba020041b3') saved_at: Feb

我有两个收藏:

“用户”集合

_id: ObjectID('56c9a824f4b233dfd30041b3')
name: Luke Skywalker
username: jedimaster23

“projectInfo”集合

_id: 56d1d830f4b233ded30041c3
projectName: L
startDate: 24 April 2016
users_id: ObjectID('56c0abb7f4b233ba020041b3')
saved_at: February 27, 2016 5:09 PM
每次用户创建项目时,其用户ID都存储在projectInfo集合和users集合中,因此projectInfo集合中有一个名为user_ID的手动引用

我只是想列出每个用户创建的所有项目。我目前的问题是:

    $userTest = $user->_id; // get the userid from the current session

    $findResult = $usersCollection->findOne(array('_id'=> new MongoID($userTest)), array('user_id'=>1));//get current user

    $result = $collection->find(array('_id' => array('$in' => $findResult['user_id'])));
但是,这不会返回任何记录,尽管我知道我登录的用户创建了许多项目

有人能告诉我我做错了什么吗?这是我在MongoDB的第一个项目,所以仍处于学习阶段

为什么不这样做:

 $currentUserId = $user->_id; // get the userid from the current session

 $result = $projectCollection->find(array('users_id' => new MongoID($currentUserId));

更新为更简单的解决方案