say i have two collections in mongodb,one for users which contains users basic info,and one for apps which contains applications.now if users are allowed to add apps,and the next time when they login, the web should get the user added app for them.how should i construct this kind of database in mongodb.
users:{_id:ObjectId(),username:'username',password:'password'}
apps:{_id:ObjectId(),appname:'',developer:,description:};
and how should i get the user added app for them??? should i add something like addedAppId like:
users:{_id:ObjectId(),username:'username',password:'password',addedApppId:[]}
to indicate which app they have added,and then get the apps using addedAppId???
Yep, there’s nothing wrong with the
userscollection keeping track of which apps a user has added like you’ve indicated.This is known as
linkingin MongoDB. In a relational system you’d probably create a separate table,added_apps, which had a user ID, app ID and any other relevant information. But since you can’t join, keeping this information in theuserscollection is entirely appropriate.From the docs:
(this is the extra bit you’d need to do, fetch app information from the user’s stored
AppId.)…