문제

We are developing a web application that will serve multiple clients. Each client will have multiple users. We'd like to design our model schema something like this:

  1. Client 1
    1. User 1-1
    2. User 1-2
    3. User 1-3
  2. Client 2
    1. User 2-1
    2. User 2-2
    3. User 2-3
  3. etc...

I have two concerns as we are writing this in Django aided by MongoEngine. By nesting our users (which in turn are the logins), is this a pain as far as authentication? In other words does MongoEngine support this type of schema? And will it be possible somehow to attach the current Client object to the request parameter?

도움이 되었습니까?

해결책

How you will query the code and use the data should help drive how to design the schema.

What will the query be to log a user in? It is possible to match against a whole document ($elemMatch) and if stored in a list you'd have to do that. Otherwise you could match against User1 username and User2 password if using dot notation.

So you could use that schema but you have to be careful and probably isn't best practise, especially if you want to look at the nested user object it would be cumbersome. Also having large unbounded Lists will not perform well.

As for adding the user to the request context - you can always create your own context to do that.

It might be better to flip it and use the authentication frameworks in Django but add the client to a user.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top