Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It does only use one connection, if you use the default method where you do mongoose.connect(). To get around this, you can create multiple connections, and then tie a model pointing to the same schema to that connection.</p> <p>Like so:</p> <pre><code>var conn = mongoose.createConnection('mongodb://localhost/test'); var conn2 = mongoose.createConnection('mongodb://localhost/test'); var model1 = conn.model('Model', Schema); var model2 = conn2.model('Model', Schema); model1.find({long query}, function() { console.log("this will print out last"); }); model2.find({short query}, function() { console.log("this will print out first"); }); </code></pre> <p>Hope that helps.</p> <p><strong>Update</strong> Hey, that does work. Updating from the comments, you can create a connection pool using createConnection. It lets you do multiple queries from the same model concurrently:</p> <pre><code>var conn = mongoose.createConnection('mongodb://localhost/test', {server:{poolSize:2}}); var model = conn.model('Model', Schema); model.find({long query}, function() { console.log("this will print out last"); }); model.find({short query}, function() { console.log("this will print out first"); }); </code></pre> <p><strong>Update 2 -- Dec 2012</strong><br> This answer may be slightly outdated now--I noticed I've been continuing to get upvotes, so I thought I would update it. The mongodb-native driver that mongoose wraps now has a default connection pool size of 5, so you probably don't need to explicitly specify it in mongoose.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload