0

I want to create only the collections structure. i.e. Say Products collection contains a list of Categories.

I want to specify this container structure by creating this dependencies, but I do not want to create any collection entry (say there is a loader program somewhere that bulk uploads the data).

The closet analogy in RDBMS is; DBA creates the schema design with constraints and dependencies; application or ETL tool loads the actual data.

Most of the examples that I see simply create a sample collection and then invoke the db.insert(document) OR db.save(document)

Is it even possible in MongoDB?

if the question is not clear, please let me know.

Thanks

Ayusman
  • 8,509
  • 21
  • 79
  • 132
  • While going through the book "MongDB: The Definitive Guide" under section 2.2.1, I cam e across this statements: collection can have any number of different shapes. For example, both of the following documents could be stored in a single collection: {"greeting" : "Hello, world!"} {"foo" : 5} Till I discover more details. – Ayusman Apr 10 '12 at 20:59

1 Answers1

3

The short answer is NO.

You cannot create a schema in MongoDB. A collection is just a set of documents. Furthermore, dependencies are likely to be represented with embedded documents (as opposed to referenced documents).

We can be more specific if you post the data you want to represent.

Blacksad
  • 14,906
  • 15
  • 70
  • 81
  • So what you are saying is I can not create a set of document structures and expect other applications to fill in the data as needed. Every time I need a document structure I MUST create a document with data (dummy or real) for the document to be inserted into Mongo. I can not create a document structure (like creating a table) with references. I do understand that Mongo is schema less; what I find odd is not being able to publish some kind of structure for my data. – Ayusman Apr 10 '12 at 17:18
  • So what is the use of Collections? I visualized collections as analogus to Tables in RDBMS. I define the collections structure and all documents belonging to this collection will have the same format. May be I got my basics wrong :-( – Ayusman Apr 10 '12 at 17:21
  • Well yes, schema-less means schema-less... there is no requirement whatsoever for documents in a given collection to have a common structure. This is the power of schema-less DBs... – Blacksad Apr 10 '12 at 18:14