我想在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