Home How can we form a mongoDB schema object in JavaScript for the JSON where keys are changing dynamically?
Reply: 0

How can we form a mongoDB schema object in JavaScript for the JSON where keys are changing dynamically?

user788
1#
user788 Published in May 23, 2018, 4:39 pm

I want to create a schema in mongoDB for using in an AngularJS project. But the keys for the json are changing dynamically. The json is like this:

{

    “1” : {

         “Name” : “John”,

         “City” : “London”

     },

    “2” : {

         “Name” : “Paul”,

         "City” : “New York”

      }

}

Here the keys are changing. They will always be in integer format for sure. For the values, I can have my schema like this: (using Javascript)

var dbObject = new Schema({
    Name: String,
    City: String
});

I am not sure how to include the key which will always be an Integer in this schema. Any pointers for creation of such a schema object in mongoDB?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.243332 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO