2017-02-11 20 views
0

我看到猫鼬对象上有很多属性。当我console.log(mongoose)我不认为重要的东西(普通有用的东西)如何控制`mongoose`的属性。在哪里寻找猫鼬属性?

我看到

Mongoose { 
    connections: 
    [ NativeConnection { 
     base: [Circular], 
     collections: {}, 
     models: {}, 
     config: [Object], 
     replica: false, 
     hosts: null, 
     host: 'localhost', 
     port: 27017, 
     user: undefined, 
     pass: undefined, 
     name: 'mytest', 
     options: [Object], 
     otherDbs: [], 
     _readyState: 2, 
     _closeCalled: false, 
     _hasOpened: false, 
     _listening: false, 
     db: [Object] } ], 
    plugins: [], 
    models: {}, 
    modelSchemas: {}, 
    options: { pluralization: true } } 

它显示了一个连接对象猫鼬对象内,但我在寻找 这个东西

console.log(mongoose.connection.readyState) 
var gfs = Grid(mongoose.connection.db, mongoose.mongo); 
//I could only set up GRIDFS using those paramaters 

没有connection对象(单数),并没有mongo对象,我一个mongoose对象上看到的。

mongoose.mongo做什么和mongoose.connection.db。他们为什么不同?

我在猫鼬API中找不到mongoose.mongo

而且我在数据库中的集合,但其生产{}

我真的很想看到connectionmongo财产时,我做了console.log(mongoose)。为什么不在那里?

回答

0

试试这个片断

// Data base connection 
mongoose.connect(mongoURI, (err) => { 
    if (err) { 
     console.log(chalk.bold.red('Please check you MongoDB instance connection')); 
    } 
}); 

const connection = mongoose.connection; 

const Grid = require('gridfs-stream'); 
Grid.mongo = mongoose.mongo;