Using help references is excellent - even recommended. Use DbRefs if they offer certain advantages - for example, allowing automatic de-linking (a mongo script or php code can automatically know that the points foo are in the collection x, with id y [in the z database]).
Different types - poor design
However, avoid type manipulation.
Having something that is actually a foreign key in one collection, and it differs from the type of collection that it points to, is a bad design. A type of juggling is something that can be excluded from development in general, rather than introduced.
Think of a database
Code like this worked on db, should work:
form = db.forms.findOne(); user = db.users.findOne({_id: form.user_id});
And it shouldn’t make any difference what type is the _id user collection field. With the schema in question, this code will look like this:
form = db.forms.findOne(); user = db.users.findOne({_id: new MongoId(form.user_id)});
In fact, this is not a huge difference, but it means that you should think / remember to convert these links, and it becomes problematic if / when a collection is created that uses a different type - it introduces inconsistencies.
Consider the following:
> school = db.schools.insert({_id: 123, name: "my school"}); > userId = new ObjectId(); > db.users.insert({_id: userId, name: "Me"}); > db.forms.insert({user_id: userId, school_id: 123});
Let's say that the school identifier is a unique code. if it is not possible to change this, it is appropriate and a good idea to use _id as the field. Now the school ID and user ID are different types:
> db.forms.findOne(); { "_id" : ObjectId("508940370392baf87e68e31d"), "user_id" : ObjectId("5089401c0392baf87e68e31b"), "school_id" : 123 }
If they are stored as-is, it is still possible to completely ignore these different types in the queries:
form = db.forms.findOne(); school = db.schools.findOne({_id: form.school_id}); user = db.users.findOne({_id: form.user_id});
If different types are used, this means that there is a need to think "with this collection I need to convert the string to ObjectId, but with this I should not."
This is a problem that could have been avoided, but was introduced instead.