0

since mongoDB does not support foreign keys, I've read that you can use for DBReF. Now I want to like to test this relationship.

The 2 collections are



db.professor.insert({"_id": 1122, "Name":"Heinrich","Rang": "C3","Raum":"D123"})

db.assistent.insert({"_id": 2244,"Name":"Schmidt","Fachgebiet":"Neuronale Netze","Boss":{"$ref":"professor","$id":1122}})

First question, but it should not be at the reference the wrong id may assume or. And if I entries with the correct ID $ id how can I test the reference?

Background is that I examine the data integrity features mongoDB! Does anyone have sources on mongoDB and data integrity

Community
  • 1
  • 1
viv1d
  • 339
  • 4
  • 5
  • 12

1 Answers1

1

MongoDBs inter collection data integrity is zero. This is not a bug in the way MongoDB works nor is it desired that this behaviour should change.

Not having inter collection data integrity is one of its core features as a NoSQL ( http://en.wikipedia.org/wiki/NoSQL ) product which this behaviour is commonly associated with (that being said it doesn't have to).

Of course this has nothing to do with general data integrity but cascading and referencing of relationships server-side.

A DBRef ( http://docs.mongodb.org/manual/applications/database-references/ ) is no different to just saving a ObjectId into your document. The only real difference is that it is a object of objects which also store a property to house the collection name. There is nothing special about the DBRef except that it comes pre-bundled with the MongoDB driver for most (if not all) languages as a helper to allow you to query the other row in your application.

Many do confuse the purpose of a DBRef however I assure you that there is nothing truly special about it.

So there is no check to see if you put in the wrong ObjectId and there is no cascade on the relationship and there is no "foreign key" behaviour in MongoDB.

Any and all relational integrity comes from your application and its ability to work in such a manner that prevents any problems within your data. This applies to both inserts and cascades of pseudo relations.

Considering these brief facts about MongoDB your test is almost useless, if you wish to test the data integrity of a relational model you should use a relational database.

Sammaye
  • 43,242
  • 7
  • 104
  • 146