문제

All i get from this code:

var views = db.books.find({"number":1}, {"views":1, _id:0}); console.log(views);

is this response:

{ _readableState:
  { highWaterMark: 16384,
    buffer: [],
    length: 0,
    pipes: null,
    pipesCount: 0,
    flowing: false,
    ended: false,
    endEmitted: false,
    reading: false,
    calledRead: false,
    sync: true,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    objectMode: true,
    defaultEncoding: 'utf8',
    ranOut: false,
    awaitDrain: 0,
    readingMore: false,
    decoder: null,
    encoding: null },
 readable: true,
 domain: null,
 _events: {},
 _maxListeners: 10,
 _get: [Function] }
도움이 되었습니까?

해결책

You can use .findOne to return a single instance and get the result.

Find assumes you're querying for a collection of documents and return a cursor:

You can for example, convert it to an array:

db.books.find({"number":1}, {"views":1, _id:0}).toArray(function(err, results){
    console.log(results);
});

You can use .each to iterate through elements and .nextObject to get the next, they're all asynchronous obviously being IO operations in nodejs, here is the section on cursors in the manual.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top