Coder Social home page Coder Social logo

co-mongo's People

Contributors

thomseddon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

co-mongo's Issues

Fetching a collection using defaults should not require the use of `yield`.

Hi @thomseddon, when you say:

Not all methods should be yielded, the rule is: if the methods accepts a callback (e.g. collection.insert()), yield it, if it doesn't (e.g. collection.find()) don't.

Please correct me if I'm wrong but according to this docs, fetching a mongodb collection using defaults (specifically {strict: false}), the use of yield should not be necessary. For example doing something like this with thunkify should work:

var MongoClient = require("mongodb").MongoClient
, thunkify = require("thunkify")
, co = require('co')

co(function *() {
  MongoClient.connect = thunkify(MongoClient.connect)
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // fetch the collection without using yield
  var collection = db.collection("users");

  var cursor = collection.find()

  cursor.toArray = thunkify(cursor.toArray);
  var users = yield cursor.toArray()

  console.log(users)

  db.close();
});

but if you try it using co-mongo:

var comongo = require('co-mongo');
var co = require('co');

co(function *() {
  var db = yield comongo.connect('mongodb://127.0.0.1:27017/test');

  // try to fetch the collection without using yield
  var collection = db.collection('users');

  var cursor = collection.find();

  var users = yield cursor.toArray();

  console.log(users);

  db.close();
})();

it throws an error like this:

TypeError: Object function (done) {
  args.push(function (err, collection) {
    if (err) return done(err);

    if (Array.isArray(collection)) {
      collection = collection.map(function (collection) {
        return new Collection(collection);
      });
      return done(null, collection);
    }

    done(null, new Collection(collection));
  });
  db[method].apply(db, args);
} has no method 'find'

It might be a minor change but it could help to keep consistency with node-mongodb-native.
Cheers! :D

sync comongo.collection() or sync comongo.get()

Hey,

I am really glad I found this project and I think this has the potential to be the next mongodb package for node :)

This just as a small note beside. What I want to report is that I think we could make a better approach for setting up the connection and to replace the current 'connect()', 'get()', 'configure()' approach:

var comongo = require('co-mongo');

// configure as usual
comongo.configure('mongodb://localhost/test')

// this is possible SYNC !!
var users = comongo.collection('users')

// use in generator
app.use(function *(next) {
  this.body = yield users.findOne();
});

The reason why I am interested on this feature is that I would like to "get" the db or the collection in "non-generator" function to pass around.
For example as you see in the above snippet I use a module variable users to cache the collection. This is unfortunately not possible as the module is not executed in a generator function.

What do you think any suggestions?

need support for bulk

ok, this issue should be fixed easily and don't need to update "node-mongodb-native".

bulk is supported in api 1.4.x, but doesn't work with co-mongo.

we need support something like this:

var col = db.collection('my_collection');
var bulk = col.initializeUnorderedBulkOp();

//then, we can insert a lot of docs at once:
bulk.insert({_id:1, name: 1});
bulk.insert({_id:2, name: 2});
//....
yield bulk.execute();

many thanks

official api for 1.4.x:
http://mongodb.github.io/node-mongodb-native/1.4/api-generated/collection.html?highlight=bulk#initializeUnorderedBulkOp

Add repository to package.json

Great library. Took a while to find - I assumed it was on GitHub (what isn't) but co-mongo returns a lot of items. Had to use Google with "site:github.com"...

Memory Consumption in insert method

I am executing below code around 1Million times and Memory consumed by "insert" gradually get increased and program aborted when all memory consumed.
var item = yield productsCollection.insert( p );

can you fix this issue ?

Below is the screenshot of heapdump and its all filled with db objects. If i comment out insert code, loop runs fine till 10 million

http://tinypic.com/r/2qx6jrd/8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.