MongoDB, Using Mongodb ObjectID between collections

mongodb, php

Solution

Now I am not familiar with PHP but the schema design that you have suggested is good.I am using a similar structure for my c# implementation.Just to be clear here is a sample of my schema design

Account Class

public  ObjectId Id{get;set;}
public   string  Email {get;set}
public   string  Password{get;set;}

User Class

 public ObjectId Id{get;set;} 
 public string  AccountId {get;set}//refers to the ID in the account.

Now if I want to query an account for any user I can simply query it using the accountId in the user class.

MongoDb calls this referencing technique as manual referencing and this is also the one that it recommends here is the link http://docs.mongodb.org/manual/applications/database-references/

Problem

Using PHP and MongoDB, i have a collection called users and another one called forms in the same DB. I am using the Mongodb ObjectID as user identifier for the documents in the forms collection, saving the users ObjectId as uid on each forms document. I am going to create an index of the uid field in the forms collection, but my question is how i should save the users Objectid? As of now I am saving it as a normal string like (simplified) ``` $collection->insert( array('formName'=>'The name','uid'=>'CURRENT_USERS_ObjectId_AS_string') ); ``` Does this seem logic or is best practice in this case to create a Mongodb ObjectID for uid like ``` $collection->insert( array('formName'=>'The name','uid'=> new MongoId('CURRENT_USERS_ObjectId_AS_string')) ); ```

Original source