I am trying to do this query but in fuel:
var user = db.users.findOne({username: 'jacinto'})
db.products.find({_id:{$in: user.productIds}})
My guess was something like this:
First Query:
$mongodb->select(array('name',
'username',
'avatar',
'productIds'));
$mongodb->where(array('username' =>'jacinto'));
$output = $mongodb->get_one('users');
Second Query:
$mongodb = \Mongo_Db::instance();
$mongodb->where_in('_id', $output);
$cabinet = $mongodb->get('products');
but I cant seem to get it to find by the id. Even if I manually put in:
$mongodb = \Mongo_Db::instance();
$mongodb->where_in('_id', array('ObjectId("4f983fc40f8efaa7a1cb10ba")', '4f983fc40f8efaa7a1cb10b9'));
$cabinet = $mongodb->get('products');
Any help would be greatly appreciated.
Thanks
Hey, when querying for ObjectID's, you need to use the php Object/Type MongoID such as
<code>
public function action_getstuff()
{
$mongodb= \Mongo_Db::instance('default');
$userID1 = '4f98c2f6f26c618f21000002';
$userID2 = '4f976a38f26c619121000002';
$result = $mongodb->where_in('_id', array($userID1, $userID2))->get('Users');
if($result)
{
echo "got Results with userID strings<br> ";
}
$result = null;
$mongoID1 = new MongoID($userID1);
$mongoID2 = new MongoID($userID2);
$result = $mongodb->where_in('_id', array($mongoID1, $mongoID2))->get('Users');
if($result)
{
echo "got Results with MongoID objects<br>";
}
}
</code>