mongodbConnect

MongoDb extension; I’m hoping someone can explain what ‘pools connection
returned’ means.

Function MONGODBCONNECT
Connects to a MongoDB and pools connection returned

What I’ve been doing is in onApplicationStart()

application.db1 = mongodbConnect(“mydb”,“localhost”,27017);

and then using application.db1 in my app as necessary as a sort of
datasource, eg:

application.db1[“coll1”].insert(a_struct_I_made_earlier);

This is all fine (so far, only a tiny db), but if I do a dump of the
application scope I see db1 is a representation of the entire db1 database
which is obviously not good.

I suppose the simplest example is <cfdump
var=‘#mongodbConnect(“mydb”,“localhost”,27017)#’)>

How am I supposed to be doing this?

Thanks

Richard

No, that’s how the extension is set up. If you dump the connections, without a “top” argument, you’re going to see the full representation, including all of your collections, as a struct. If you dump the metadata of the connection, though, you’ll see it’s actually a native class “org.lucee.mongodb.DBImpl”. You’ll be able to see the methods that way without the dump normalizing the entire database.

Once you’ve created your connection, though, should always perform your operations on the collections (use these in your Models):

var myCollection = application.db1.getCollection(“col1”);

myCollection.insert({“test”:“123”});
var cursor = myCollection.find();
while(cursor.hasNext()){
var document = cursor.next();
//do stuff here
}On October 18, 2015 at 6:16:53 AM, Richard Meredith-Hardy (@Richard_Meredith-Har) wrote:

MongoDb extension; I’m hoping someone can explain what ‘pools connection returned’ means.

Function MONGODBCONNECT

Connects to a MongoDB and pools connection returned

What I’ve been doing is in onApplicationStart()

application.db1 = mongodbConnect(“mydb”,“localhost”,27017);

and then using application.db1 in my app as necessary as a sort of datasource, eg:

application.db1[“coll1”].insert(a_struct_I_made_earlier);

This is all fine (so far, only a tiny db), but if I do a dump of the application scope I see db1 is a representation of the entire db1 database which is obviously not good.

I suppose the simplest example is <cfdump var=‘#mongodbConnect(“mydb”,“localhost”,27017)#’)>

How am I supposed to be doing this?

Thanks

Richard


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/

You received this message because you are subscribed to the Google Groups “Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/0ac2b671-9537-46bf-a9e1-6b0131fdc857%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hmm

I think what you’re saying is that if you do this:

application.db1 = mongodbConnect(“mydb”,“localhost”,27017);

the db isn’t actually sitting there in the application scope as a giant
struct containing the entire db, it only appears like that if you dump it.

So in fact what I’m doing is OK?

Seems that

var myCollection = application.db1.getCollection(“col1”);

is the same as

var myCollection = application.db1[“col1”];

so you can do

application.db1[“coll1”].insert(a_struct_I_made_earlier);

or

application.db1.getCollection(“col1”).insert(a_struct_I_made_earlier);

and it’s all the same thing.

Or am I missing the point?

thanks

RichardOn Sunday, 18 October 2015 14:48:18 UTC+1, Jon Clausen wrote:

No, that’s how the extension is set up. If you dump the connections,
without a “top” argument, you’re going to see the full representation,
including all of your collections, as a struct. If you dump the metadata of
the connection, though, you’ll see it’s actually a native class
“org.lucee.mongodb.DBImpl”. You’ll be able to see the methods that way
without the dump normalizing the entire database.

Once you’ve created your connection, though, should always perform your
operations on the collections (use these in your Models):

var myCollection = application.db1.getCollection(“col1”);

myCollection.insert({“test”:“123”});
var cursor = myCollection.find();
while(cursor.hasNext()){
var document = cursor.next();
//do stuff here
}

On October 18, 2015 at 6:16:53 AM, Richard Meredith-Hardy ( r....@flymicro.com <javascript:>) wrote:

MongoDb extension; I’m hoping someone can explain what ‘pools connection
returned’ means.

Function MONGODBCONNECT
Connects to a MongoDB and pools connection returned

What I’ve been doing is in onApplicationStart()

application.db1 = mongodbConnect(“mydb”,“localhost”,27017);

and then using application.db1 in my app as necessary as a sort of
datasource, eg:

application.db1[“coll1”].insert(a_struct_I_made_earlier);

This is all fine (so far, only a tiny db), but if I do a dump of the
application scope I see db1 is a representation of the entire db1 database
which is obviously not good.

I suppose the simplest example is <cfdump
var=‘#mongodbConnect(“mydb”,“localhost”,27017)#’)>

How am I supposed to be doing this?

Thanks

Richard


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your
ticket NOW - http://www.cfcamp.org/

You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+un...@googlegroups.com <javascript:>.
To post to this group, send email to lu...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/0ac2b671-9537-46bf-a9e1-6b0131fdc857%40googlegroups.com
https://groups.google.com/d/msgid/lucee/0ac2b671-9537-46bf-a9e1-6b0131fdc857%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

That’s correct. It’s only showing it if you dump it. Same sort of thing happens when you dump an ORM entity with complex relationships - which is why you should never dump one without a “top” argument.

Using struct key notation for your collections works as well. Just a matter of preference.

Jon> On Oct 18, 2015, at 12:26 PM, Richard Meredith-Hardy <@Richard_Meredith-Har> wrote:

hmm

I think what you’re saying is that if you do this:

application.db1 = mongodbConnect(“mydb”,“localhost”,27017);

the db isn’t actually sitting there in the application scope as a giant struct containing the entire db, it only appears like that if you dump it.

So in fact what I’m doing is OK?

Seems that
var myCollection = application.db1.getCollection(“col1”);
is the same as
var myCollection = application.db1[“col1”];
so you can do
application.db1[“coll1”].insert(a_struct_I_made_earlier);
or
application.db1.getCollection(“col1”).insert(a_struct_I_made_earlier);
and it’s all the same thing.

Or am I missing the point?

thanks

Richard

On Sunday, 18 October 2015 14:48:18 UTC+1, Jon Clausen wrote:
No, that’s how the extension is set up. If you dump the connections, without a “top” argument, you’re going to see the full representation, including all of your collections, as a struct. If you dump the metadata of the connection, though, you’ll see it’s actually a native class “org.lucee.mongodb.DBImpl”. You’ll be able to see the methods that way without the dump normalizing the entire database.

Once you’ve created your connection, though, should always perform your operations on the collections (use these in your Models):

var myCollection = application.db1.getCollection(“col1”);

myCollection.insert({“test”:“123”});
var cursor = myCollection.find();
while(cursor.hasNext()){
var document = cursor.next();
//do stuff here
}

On October 18, 2015 at 6:16:53 AM, Richard Meredith-Hardy (r....@flymicro.com) wrote:

MongoDb extension; I’m hoping someone can explain what ‘pools connection returned’ means.

Function MONGODBCONNECT

Connects to a MongoDB and pools connection returned

What I’ve been doing is in onApplicationStart()

application.db1 = mongodbConnect(“mydb”,“localhost”,27017);

and then using application.db1 in my app as necessary as a sort of datasource, eg:

application.db1[“coll1”].insert(a_struct_I_made_earlier);

This is all fine (so far, only a tiny db), but if I do a dump of the application scope I see db1 is a representation of the entire db1 database which is obviously not good.

I suppose the simplest example is <cfdump var=‘#mongodbConnect(“mydb”,“localhost”,27017)#’)>

How am I supposed to be doing this?

Thanks

Richard


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/

You received this message because you are subscribed to the Google Groups “Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/0ac2b671-9537-46bf-a9e1-6b0131fdc857%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/

You received this message because you are subscribed to the Google Groups “Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/6e0bf2fc-7378-4bb1-8e2c-1327a1f5cb8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.