-1

I have a basic question about creating a physical schema of a collection in MongoDB.

Can I create a MongoDB document without values. At this point I just know the keys and some data types. But I do not have the values. Is it possible to create a schema, where O just have place holders for values?

  • For string, I can put "" or "abc" (dummy value) as place holder for values.
  • For decimal I can do the same. Put 123.1 as dummy value.
  • For Boolean I can put true or false as dummy value
  • For date I can put "01-01-1900" as dummy value

But putting such dummy values becomes complex when I have hundreds of fields, particularly nested ones such as document within a document or arrays.

I am trying to find a SQL world equivalent of "create table" where we can create physical schema, without putting the values

Any advice?

Thanks Aurobindo

Aurobindo
  • 11
  • 5
  • 1
    *"basic question about creating a physical schema "* -- Basic Answer, MongoDB has **no schema**. There is no such thing as "strict types or naming", and each document can indeed be totally different as far as the "database" ( MongoDB ) is concerned. Schema is delegated to your "application domain logic". This is an intentional departure from "create table" and it simply does not exist. So stop looking. – Neil Lunn Oct 24 '17 at 07:24
  • Hi, Thanks for your answer. But is it right to say no schema at all. In any enterprise data set, I believe there will be some commonality between every record. For example as each record flow in there will be an id field, or a name field, and so on. But you are right schema is flexible. But flexible does not mean each record has no overlap of attributes with other record. I am trying to come up with a schema for the attribute sets that are common across documents. – Aurobindo Oct 24 '17 at 07:36
  • **MongoDB has no schema**. There in bold so it hopefully sinks in. "Commonality" is for your API, and not MongoDB. That's the philosophy in a nutshell and a key difference. Schema and triggers and Referential Integrity and all of those things "simply do not exist" in MongoDB. That is actually the whole point of the design. So not the Database, but your software layer that looks after those things instead. Or doesn't – Neil Lunn Oct 24 '17 at 07:42
  • Understand that MongoDB has no schema. Does this mean no physical model till I insert a document? – Aurobindo Oct 24 '17 at 07:56

1 Answers1

0

If you want, you can insert a document with any content (you can insert only part of elements or even empty document). MongoDB is a document-oriented database, where each document can be absolutelly different.

Forget everything what you know about RDBMS, because this knowledge is absolutely useless in MongoDB world.

Neodan
  • 5,154
  • 2
  • 27
  • 38
  • I am given a task to create physical model for Mongo. I have a UML that shows the nature of the expected records, vix the <>, attributes, their data types, and <> How do I start with a physical model if I consider every document is flexible ? I create a collection, from that point onward, document (equivalent to record) .... has absolutely no defined schema ..... what is the use of the UML diagram then? Don't I need the keys to create indexes. The problem is I do not have real records (documents) with me. ... with that how can I make Physical Model happen? – Aurobindo Oct 24 '17 at 07:51
  • Your model can skip an empty elements (don't store into MongoDB) or just set a empty/default values for the document elements (it would be a column equivalents in SQL). There is a lot of ways how you can solve your problem, but the best option depends on the details of your project. – Neodan Oct 24 '17 at 08:07