Design – MongoDB Embedded vs Reference Private info

designmongodbschema

I have searched extensively for a similar Mongo schema design and can't find relevant examples.

I have a store (with public info), each store has an account (with private account info).

// store object
{
  name: "Departement Store",
  email: "contact@store.com",
  account: { // private info not returned by API
    manager: "Steve",
    employees: [...]
  }
}

The stores will be searched through a public API. I am limiting the search queries using MongoDB's features to limit the returned data:

db.stores.find({}, {account:0});

My question: is it more efficient to keep the private data as a subdocument or in a separate collection? It seems a separate collection with account info is the best choice as I will be picking and choosing from an embedded document.

References:

Best Answer

As an update, this question was answered here: https://groups.google.com/forum/#!topic/mongodb-user/-1eXvkoxHUw

Summary: Keep data in one document, restrict data using MongoDB's built-in projection feature.

Related Topic