I'm going to build a new auth syystem, and I really like to use CouchBase
For now I have load of questions, please execute me if I should not shot 
them all on a single topic like this!

1. Should I store all kind of object in a single bucket?
I have search and find many answers on SO that saying yes, but also found 
this note on CouchBase "Views best practices 
<http://docs.couchbase.com/4.0/views/views-writing-views.html>"
I not a really good idea for a large database. What I wonder is if our db 
can be that 'large': What we (will) have:

   - 1 milions user object.
   - Whenever user login, a token object will be make and maybe keep for 
    month. User can login at the same time on mutilple devices so they will 
   have many token object.
   - A few meta-data object like user role and role's permissions.

2. Do we have a limit size for a document? For example I want to append a 
login_logs to user object like this
Example user object:

> {
>   "id": "<uuid>", //meta id
>   "type": "user",
>   "emails": [
>     {"address": "....", "confirmed": true},
>      {"address": "....", "confirmed": true},
>   ],
>   "password": {hash: ".....", "salt": "...."}
>   "login_logs": [
>     {....},
>     {...}
>   ]
> }


If we have a size limit, I may need to split the login_logs to diffrent 
object and do all kind of indexing.
2.b With the Golang gocb, can I get just a part of document?

3. Can I call 'emit' multilple time in the map function?
Let assuming if I store all kind of object in a same bucket.
And assumming that I need to separate user, login_logs, and token in 
different object:
Because CouchBase document say that I should not have to many views, and I 
want to query these:

   - Check if email and password correct.
   - Find the user with that token, if the token not expire yet.
   - List all login history of an user order by login time.

Example login_log object:

> {
>   "type": "login_logs",
>   "createdOn": "JSON iso string time",
>   "user_id": "<guuid>",
>   "device": "sone string"
> }

Example token object:

> {
>   "type": "token"
>   "id": "<the token string>", // the meta id
>   "exprire": "JSON iso string",
>   "user_id": "<uuid>",
>   "device": "some string"
> }


And if I have ONLY ONE map functiion that:

> function(doc, meta) {
>   switch(doc.type) {
>     case "token":
>       emit([meta.id, dateToArray(doc.exprire)], doc.user_id);
>       break;
>     case "login_logs":
>       emit([dateToArray(doc.createdOn), doc.user_id]);
>       break;
>     case "user":
>       for(i = 0; i<doc.emailes.length; i++) {
>         if(doc.emailes[i].confirmed)
>           emit(doc.emailes[i].address, doc.password);
>       }
>       break;
>   }
> }

Will this affected performance? Disk is cheap, I more care about speed (RAm 
and CPU more expensive I think)


4. How to atomic "create if not found"? 
For example I want to check if the user input email are already exist or 
not, then if only not found, save that user object to CouchBase.

5. Will using N1QL save my life (for my need)? How to compare N1QL GSI 
performance with View?

6. With N1QL, can I create an index like this:

> CREATE INDEX fooOverBar ON `sample`(foo,bar) WHERE foo > bar USING GSI;


-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to couchbase+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to