I am having trouble getting the node-mongodb-native drivers to play nice. I've installed 开发者_如何学Pythoneverything, all tests run correctly but when I try and run any of the examples I get a null error on the function. e.g.:
TypeError: Cannot call method 'remove' of null
Mongo shows that a connection is made, a function called then the connection closes. I have tried mongodb 1.4.5, 1.6.5 and 1.8.1 all with the same result.
Is there something else I should be doing to get the examples to run?
This means that you are trying to do a remove
but the collection did not initialize correctly.
I assembled some sample code for a Node.JS + MongoDB + CloudFoundry blog post. There's also some sample code on GitHub. The code is designed to work without CloudFoundry and simply run locally.
Take a look at the code that does the basic find:
require('mongodb').connect(mongourl, function(err, conn){
conn.collection('ips', function(err, coll){
coll.find({}, {limit:10, sort:[['_id','desc']]}, function(err, cursor){
cursor.toArray(function(err, items){...
Take a look at coll.find
, I'm assuming that coll
is correctly initialized. There's a chance that it may not be initialized. If so, check the err
variable and see what you're getting. Also check the err
variable at the level above that.
精彩评论