我没有从mongodb的集合中获取正确的对象

时间:2017-08-22 12:07:32

标签: node.js mongodb

这是我获取集合中所有文档/对象的代码。我尝试了其他方法。我正在使用nodejs和express。我能够插入文件但我无法检索它们。正确方向的任何一点都非常感谢。

 MongoClient.connect(url, function (err, db) {
        var cursor = db.collection('games').find({});
        console.log(cursor);
        db.close();
 });

这是我希望看到的对象类型:

var game = {
        game_name: data.roomName,
        players: [{
            scktID: socket.id,
            name: "player1",
            score: 0,
            cards: [],
        }],
        card_count: 0,
        trump_suit: "na",
        current_player: 0,
        game_started: false
    };

不幸的是我收到了这个(缩短版本):

Cursor {
  pool: null,
  server: null,
  disconnectHandler:
   Store {
     s: { storedOps: [], storeOptions: [Object], topology: [Object] },
     length: [Getter] },
  bson: BSON {},
  ns: 'mydb.games',
  cmd:
   { find: 'mydb.games',
     limit: 0,
     skip: 0,
     query: {},
     readPreference: ReadPreference { preference: 'primary', tags: undefined, options: [Object] },
     slaveOk: true },
  options:
   { readPreference: ReadPreference { preference: 'primary', tags: undefined, options: [Object] },
     skip: 0,
     limit: 0,
     raw: undefined,
     hint: null,
     timeout: undefined,
     slaveOk: true,
     db:
      Db {
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        s: [Object],
        serverConfig: [Getter],
        bufferMaxEntries: [Getter],
        databaseName: [Getter] },
     promiseLibrary: [Function: Promise],
     disconnectHandler: Store { s: [Object], length: [Getter] } },
  topology:
   Server {
     domain: nul . . .

我正在使用nodejs,express和mongodb。

0 个答案:

没有答案