You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Stefan Klein <st...@gmail.com> on 2015/12/15 14:36:03 UTC

map function - any access to the DB name?

Hi CouchDB Users,

we are using one db per user, the db name and the user name are directly
related.
There are multiple daemons on server side which pass documents between
these dbs.
Each document got multiple "owner" (it's not exactly like that, but good
enough to explain) i want to create a view of documents that are no longer
"owned" by a user and can be deleted from his db.

Is there any way to get the name of the database (in our case the user the
db belongs to) in a map function?

I could emit the "owner" as key, but as i said, i simplified the task i
want to solve and the key is needed for something else.
Even with using an array as key i do not see a nice way to handle that.

regards,
Stefan

Re: map function - any access to the DB name?

Posted by Stefan Klein <st...@gmail.com>.
Hi Ingo,

2015-12-15 14:47 GMT+01:00 Ingo Radatz <th...@googlemail.com>:

> Hi Stefan,
>
> ‘this’ in the map function is the ddoc in which the view is stored. As
> long as you place the information in the ddoc you can access it in the map
> function.
>
>
I remembered that, but it seam the context is no longer set. At least for
my local 1.6.1 couchdb log(this) in a map logs "null". (log(this) in a
commonjs module logs {} though)

-- 
Stefan

Re: map function - any access to the DB name?

Posted by Ingo Radatz <th...@googlemail.com>.
Hi Stefan,

‘this’ in the map function is the ddoc in which the view is stored. As long as you place the information in the ddoc you can access it in the map function.

Maybe thats an option for you.

Ingo

> On 15 Dec 2015, at 14:36, Stefan Klein <st...@gmail.com> wrote:
> 
> Hi CouchDB Users,
> 
> we are using one db per user, the db name and the user name are directly
> related.
> There are multiple daemons on server side which pass documents between
> these dbs.
> Each document got multiple "owner" (it's not exactly like that, but good
> enough to explain) i want to create a view of documents that are no longer
> "owned" by a user and can be deleted from his db.
> 
> Is there any way to get the name of the database (in our case the user the
> db belongs to) in a map function?
> 
> I could emit the "owner" as key, but as i said, i simplified the task i
> want to solve and the key is needed for something else.
> Even with using an array as key i do not see a nice way to handle that.
> 
> regards,
> Stefan