dbref

How to query through a DBRef in MongoDB/pymongo?

Is it possible to query through a DBRef using a single find spec? user collection { 'age': 30 } post collection { 'user': DBRef('user', ...) } Is it possible to query for all post who's users are 30 in a single find step? If not, would it be wise to create a javascript function to handle the multi-stage operation or will ...

Can DBRefs contain additional fields?

I've encountered several situations when using MongoDB that require the use of DBRefs. However, I'd also like to cache some fields from the referenced document in the DBRef itself. {$ref:'user', $id:'10285102912A', username:'Soviut'} For example, I may want to have the username available even though the user document is referenced. ...

How to manually create a DBRef using pymongo?

I want to create a DBRef manually so that I can add an additional field to it. However, when I try to pass the following: {'$ref': 'projects', '$id': '1029412409721', 'project_name': 'My Project'} Pymongo raises an error: pymongo.errors.InvalidName: key '$id' must not start with '$' It would seem that pymongo reserve the $ for the...

MongoDB DBRef ON DELETE CASCADE

Is there a way in MongoDB to have a foreign key with a 'ON DELETE CASCADE' functionality? I know you can use DBRef as a sort of foreign key but when the item in a collection where the reference points to is removed, the reference returns null. But i want that the item where the reference belongs to gets removed. How do i do this? Or do...