MongoDB $lookup with _id as a foreignField in PHP

前端 未结 1 1904
别跟我提以往
别跟我提以往 2021-01-20 05:15

I am beating my head on the table for too long with this one...

I have two MongoDB collections: \"chatroom\" and \"users\". The \"chatroom\" collection has \"user_id

相关标签:
1条回答
  • 2021-01-20 05:52

    To answer my own question, I went around the problem by making "user_id" an instance of a "MongoId" class instead of a plain string. Basically, I store "user_id" as:

    $mongoObject["user_id"] = new MongoId($this->user_id);
    

    Another solution would probably be decorating the objects with "uid" field with a value equal to "_id.$id".

    0 讨论(0)
提交回复
热议问题