Best way to prepare hierarchical data for easy querying in MongoDB? -


i'm starting use mongodb new project , wanted insert customer data using scheme:

{     admin: {mail: "", realname: {first: "", last: ""}, address: {street: "", city: "", state: ""}, payment: {type: "", blz: "", account: ""}},     users: [         {mail: "", password: "", realname: {first: "", last: ""}},         ...     ],     categories: [         {name: "", assignedusers: [{id: "", readonly: true}, ...], entries: [             {name: "", tags: "", site: "", user: "", pass: "", notes: ""}         ],         ...     ] } 

however, i've found out isn't possible to, example, 1 of users in "users" array it's mail address or categories 1 user assigned id.

so seems i'd have split hierarchical data multiple collections, i'm not sure best way is. how recommend me split data?

  • you locking projection , this. optional operator specifies fields return using projection operators , it's boolean 1 - show & 0 - hide

    db.customers.findone({"users.mail": "mail@address.org"}, {users: 1})

  • that's not secure use findone({"users.mail": "mail"}) authentication, there special node.js module passportjs.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -