Schema design tips neede

15 views
Skip to first unread message

PHANI KUMAR YADAVILLI

unread,
Jun 22, 2017, 12:27:33 PM6/22/17
to mongodb-user
Hi,

I am new to the mongodb. My json string is as below. I would like to use 14691,14692 as my primary keys or unique identifiers rather than using objectid as a unique identifier. How do i achieve this using mongodb. Please help me with this.

{
"14691": {
   "refreshInterval":"10",
"ViewAvailableAttributes": ["cat","dog","goat","monkey"],
"ViewSelectedAttributes": ["cat","dog","goat","monkey"],
"ViewMandatoryAttributes": ["cat","dog","goat","monkey"],
"UploadAvailableAttributes": ["cat","dog","goat","monkey"],
"UploadSelectedAttributes": ["cat","dog","goat","monkey"],
"UploadMandatoryAttributes": ["cat","dog","goat","monkey"],
"DownloadAvailableAttributes": ["cat","dog","goat","monkey"],
"DownloadSelectedAttributes": ["cat","dog","goat","monkey"],
"DownloadMandatoryAttributes": ["cat","dog","goat","monkey"]
},
"14692": {
"refreshInterval":"20",
"ViewAvailableAttributes": ["book","ball","pen","monkey"],
"ViewSelectedAttributes": ["book","ball","pen","monkey"],
"ViewMandatoryAttributes": ["book","ball","pen","monkey"],
"UploadAvailableAttributes": ["book","ball","pen","monkey"],
"UploadSelectedAttributes": ["book","ball","pen","monkey"],
"UploadMandatoryAttributes": ["book","ball","pen","monkey"],
"DownloadAvailableAttributes": ["book","ball","pen","monkey"],
"DownloadSelectedAttributes": ["book","ball","pen","monkey"],
"DownloadMandatoryAttributes": ["book","ball","pen","monkey"]
}
}

Kevin Adistambha

unread,
Jun 27, 2017, 8:33:38 PM6/27/17
to mongodb-user

Hi Phani

I would like to use 14691,14692 as my primary keys or unique identifiers rather than using objectid as a unique identifier.

I’m not certain I understand your requirement. The _id can be thought of as a primary key of the document, and it must be unique across the collection, even if the collection is spread across multiple servers (via sharding). However, you posted a single JSON document containing two keys, each containing a large set of values. What is your use case, and how do you plan to use your data?

Please note that MongoDB schema design generally encourages you to create your schema according to your use case, as opposed to according to how the data will be stored (i.e. normal forms in relational databases). You might find the following links helpful with regard to MongoDB schema design in general:

If you just started with MongoDB, please note that we have an extensive collection of free courses available in the MongoDB University. You may find the, M001: MongoDB Basics, and M101P: MongoDB for Developers courses beneficial.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages