[node-mongodb-native] How to switch to another database?

776 views
Skip to first unread message

Joson Mandaro

unread,
Sep 29, 2010, 2:22:45 AM9/29/10
to node-mong...@googlegroups.com
Hi all,
I run the mongodb in --auth model. Then I login this server like this:
var db = new Db('admin', this.server, {});
db.authenticate(username, password);
After I logged in the server, I wanna switch to another database ( created if it doesn't exists.), and add an user account. Just like this in mongodb shell:

>db
admin
>use test1
test1
>db.addUser("Guest","123",false);

How to do this through node-mongodb-native?
Best regards,
Joson

christkv

unread,
Sep 29, 2010, 9:19:33 AM9/29/10
to node-mongodb-native
Hi Joson

It's one connection pr db. The node.js driver does not replicate the
cli interface that comes with monogo. The best location to get an
understanding of how to use the driver is

http://github.com/christkv/node-mongodb-native/blob/master/integration/integration_tests.js

Cheers

Joson Mandaro

unread,
Sep 29, 2010, 1:06:30 PM9/29/10
to node-mong...@googlegroups.com
Thanks a lot. I've seen the operation command signals for mongo driver, which are supported by mongodb. All operation commands like query, insert, update, but without "use <dababase>". 
I supposed "use" signal can be received by mongod listener beecause the mongo comand line is can do this. I'm not quite sure about this and have no idea to implement it. 
Is it feazible?

2010/9/29 christkv <chri...@gmail.com>

christkv

unread,
Oct 4, 2010, 10:02:33 AM10/4/10
to node-mongodb-native
Nope

The command line does not have anything to do with the driver. You
could certainly create the abstraction yourself but the driver does
not support it. I would not recommend it either as node.js is async
and there might be messages coming from the mongodb driver that you
have not processed yet when you suddenly switch db. Keep a connection
for each db in a hash and access on a need basis is my suggestion.

Cheers

Christian

On Sep 29, 7:06 pm, Joson Mandaro <joson.p...@gmail.com> wrote:
> Thanks a lot. I've seen the operation command signals for mongo driver,
> which are supported by mongodb. All operation commands like query, insert,
> update, but without "use <dababase>".
> I supposed "use" signal can be received by mongod listener beecause the
> mongo comand line is can do this. I'm not quite sure about this and have no
> idea to implement it.
> Is it feazible?
>
> 2010/9/29 christkv <chris...@gmail.com>
>
>
>
>
>
>
>
> > Hi Joson
>
> > It's one connection pr db. The node.js driver does not replicate the
> > cli interface that comes with monogo. The best location to get an
> > understanding of how to use the driver is
>
> >http://github.com/christkv/node-mongodb-native/blob/master/integratio...
Reply all
Reply to author
Forward
0 new messages