我想在windows 8上使用node.js设置mongodb,有谁知道为什么即时通讯得到这个错误。 C:\ users \ phill \ node_modules \ mongodb \ lib \ mongodb \ mongo_client.js:359它也说在collection = db collection ,,,不能调用null的方法'collection'。我很难设置它。我的目标是能够添加到mongo数据库,并看到我添加或拉起我添加的内容,但现在添加一些对我来说已经足够好了。我尝试了所有可以找到的东西,即使是从网站上直接找到的,我也尝试了我在这里看到的所有内容。想想也许这是我设置事物的方式。我的node.js保存在我的c:驱动器中,有一个文件说,在那里我有node_modules,npm等程序文件(86x)。路径结束于:computer> windows(C :)>程序文件(86x)> nodejs。我的Mongodb保存在我的C:驱动器上,最终成为windows(C :)> mongodb-win32-x86_64-2008plus-2.4.8。在我的C:我也创建了一个文件数据,并在其中创建了另一个数据库。我被告知我应该只使用猫鼬,我只是在学习,所以我打开任何建议,链接或任何有助于。我还有最后一个问题,我学习了PHP,然后发现了关于sql注入和类似的东西,我根本没有看到任何有关安全的内容,我应该期待同样的事情。对于这个我得到的文字没有定义,但我已经得到错误,我已经完成了,最好的是我被困在一个正确的关注屏幕上。Node.js和mongodb访问mongodb
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect("mongodb://localhost:27017/integration_test", function(err, db) {
test.equal(null, err);
test.ok(db != null);
db.collection("replicaset_mongo_client_collection").update({a:1},
{b:1}, {upsert:true}, function(err, result) {
test.equal(null, err);
test.equal(1, result);
db.close();
test.done();
});
});
尝试这样做以及和得到一个错误,C:\用户\菲尔\ node_modules \ mongodb的\ lib中\ mongodb的\ mongo_client.js:359 ....在收集=分贝收集,,,可以” t调用null的方法'collection'。即时通讯在命令提示符下调用它filename.js我将它保存在我的node.js文件所在的位置,之前我已经提取了文件并创建了一个服务器。
var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Grid = require('mongodb').Grid,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');
var db = new Db('test', new Server('localhost', 27017));
// Fetch a collection to insert document into
db.open(function(err, db) {
var collection = db.collection("simple_document_insert_collection_no_safe");
// Insert a single document
collection.insert({hello:'world_no_safe'});
// Wait for a second before finishing up, to ensure we have written the item to disk
setTimeout(function() {
// Fetch the document
collection.findOne({hello:'world_no_safe'}, function(err, item) {
assert.equal(null, err);
assert.equal('world_no_safe', item.hello);
db.close();
})
}, 100);
});
感谢,种了这通快递的工作。还没有看安全性,但将被告阅读你的链接! TY! – user3081020