Skip to content

whilefor/mongodb-co

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongodb-co

node-mongodb-native CURD will return a Promise if no callback passed, and co() returns a promise now, so we can use node-mongodb-native with co nicely.

Requirement

  • Generator
  • Promise
  • co
  • node-mongodb-native

Usage

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

	    // Insert document
	    var r = yield collection.insert({
	        hello: 'world ' + new Date().toString()
	    });
	    console.log(r.insertedCount, ' - inserted');

	    // Fetch all document
	    return yield collection.find().toArray();
	}).then(function(docs) {
	    console.log(docs.length, ' - find all');
	}, function(err) {
	    console.error(err.stack);
	});

About

node-mongodb-native with co

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published