通过mongo和mongoose进行连接时有什么区别?因为这段代码能够找到我的文档。
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mymongourl",
function (err, db) {
if (err) {
return console.dir(err);
}
var asset = db.collection('assets');
asset.find({
name: 'John'
}).toArray(function (err, items) {
console.log(items);
});
});
但是这段代码给了我'TypeError:无法读取属性'toArray'of undefined'
var mongoose = require('mongoose');
mongoose.connect('mymongourl');
var db = mongoose.connection;
var asset = db.collection('assets');
asset.find({
name: 'John'
}).toArray(function (err, items) {
console.log(items);
});