1

Is there any possibility to create the structure of an empty collection in MongoDB using mongoimport from a JSON file like the one below?

"Users" : {
"name" : "string",
"telephone" : {
    "personal": { "type": "number" },
    "job": { "type" : "number" }
},
"loc" : "array",
"friends" : "object"
}

My goal is to create a mongoDB schema from JSON files.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
Edu
  • 460
  • 12
  • 34
  • MongoDB has no schema as such what is your aim by defining the schema through JSON files. I should mention this doesn't sound like a good idea – Sammaye Feb 25 '14 at 16:32

1 Answers1

2

Yes, you can mongoimport a JSON file and if you clear out the values of those field (set them to ""), importing your JSON file should do just that.

However, MongoDB is a NoSQL database, and creating a schema in the MongoDB database doesn't really make sense. What will happen is that you'll have one record with fields whose values are empty.

Community
  • 1
  • 1
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • thanks a lot Dan, I know I have to change the RDBMS "chip", but I would need to create a schema and I dont know what is the best way, what do you advise me? – Edu Feb 25 '14 at 16:52
  • You can create the schema at the application level. For example, if you use Node.js, Mongoose supports schema definitions - http://mongoosejs.com/docs/guide.html – Dan Dascalescu Feb 25 '14 at 16:54