2017-10-17 5 views
0

몽구스 모델 인 CameraInfo가 있는데 모든 데이터가 필요합니다. 주변을 둘러보고 의미없는 기능을 보았습니다. 나는 몽고를 처음 사용합니다. Frameworks를 사용하면 모든 복잡성을 숨길 것입니다. 내 터미널에 도착몽구스 모델 데이터를 nodejs의 배열로 반환하는 방법

const mongoose = require('mongoose'); 

// Mongoose Model 
let CameraInfoSchema = mongoose.model('CameraInfo', { 
    name: { 
    type: String 
    }, 
    ipAddress: { 
    type: String 
    } 
}) 

// Data to create new schema is not shown. 

// Get Camera Model 
const CameraInfo = mongoose.model('CameraInfo'); 

// Return data as array 
CameraInfo.find({}, {limit:10}).toArray((err, data) => { 
    console.log(data); 
}) 

오류는 다음과 같습니다 당신은 몽구스를 사용하는 경우

TypeError: CameraInfo.find(...).toArray is not a function

답변

0

The toArray function exists on the Cursor class from the Native MongoDB NodeJS driver check reference node-mongodb-native

다음 콜백 함수에서 변환 할 수 있습니다

예 :

CameraInfo.find({}, {limit:10},function(err, data){ 
    console.log(data); 
}) 
관련 문제