如何使用mongodb和nodejs将文档从聚合发送到另一个页面?

时间:2019-04-20 06:15:07

标签: node.js mongodb aggregation-framework

说我有这样的场所:

{
    "_id" : ObjectId("5caf2c1642e3731464c2c79d"),
    "requested" : [],
    "roomNo" : "E0-1-09",
    "capacity" : 40,
    "venueType" : "LR(M)",
    "seatingType" : "TB",
    "slotStart" : "8:30AM",
    "slotEnd" : "9:50AM",
    "__v" : 0
}
{
    "_id" : ObjectId("5caf2e4e4a7f5222305b55dd"),
    "requested" : [],
    "roomNo" : "E0-1-10",
    "capacity" : 70,
    "venueType" : "LR(M)",
    "seatingType" : "TB",
    "slotStart" : "11:30AM",
    "slotEnd" : "12:50PM",
    "__v" : 0
}

这些场所中有一些是重复的,但是使用不同的时间段,例如:8:00PM至10:00 PM, 2:00 PM至3:20 PM。

我还想根据用户的区号(E0,E1等)将场所分开,我通过req.body.blockNo接收这些场并将其存储到变量“ blockNo”中

因此,我想分开我的收藏并将同一房间的文件发送一次到另一页。

db.getDB().collection(collection).aggregate([

    { "$match": { "roomNo": `/^${blockNo}/` } },
    { "_id": "$roomNo" }

     ],function(err, result){    

                if (!err) {

                    res.render("somePage", {
                        reservation: result,
                    });
                }
                else {
                    console.log('Error in displaying Venues :' + err);
                }
            });

当我控制台日志(结果)时

我收到了:

AggregationCursor {
  pool: null,
  server: null,
  disconnectHandler:
   Store {
     s:
      { storedOps: [], storeOptions: [Object], topology: [Server] },     length: [Getter] },
  bson: BSON {},
  ns: 'FYP.venuesches',
  cmd:
   { aggregate: 'venuesches', pipeline: [ [Object] ], cursor: {} },
  options:
   { readPreference: null,
     cursor: {},
     promiseLibrary: [Function: Promise],
     cursorFactory:
      { [Function: AggregationCursor] super_: [Function], INIT: 0, OPEN: 1, CLOSED: 2 },
     disconnectHandler: Store { s: [Object], length: [Getter] },
     topology:
      Server {
        _events: [Object],
        _eventsCount: 25,
        _maxListeners: Infinity,
        clientInfo: [Object],
        s: [Object] } },
  topology:
   Server {
     _events:
      [Object: null prototype] {
        serverOpening: [Function],
        serverDescriptionChanged: [Function],
        serverHeartbeatStarted: [Function],
        serverHeartbeatSucceeded: [Function],
        serverHeartbeatFailed: [Function],
        serverClosed: [Function],
        topologyOpening: [Function],
        topologyClosed: [Function],
        topologyDescriptionChanged: [Function],
        commandStarted: [Function],
        commandSucceeded: [Function],
        commandFailed: [Function],
        joined: [Function],
        left: [Function],
        ping: [Function],
        ha: [Function],
        authenticated: [Function],
        error: [Array],
        timeout: [Array],
        close: [Array],
        parseError: [Array],
        open: [Array],
        fullsetup: [Array],
        all: [Array],
        reconnect: [Array] },
     _eventsCount: 25,
     _maxListeners: Infinity,
     clientInfo:
      { driver: [Object],
        os: [Object],
        platform: 'Node.js v10.15.1, LE' },
     s:
      { coreTopology: [Server],
        sCapabilities: [ServerCapabilities],
        clonedOptions: [Object],
        reconnect: true,
        emitError: true,
        poolSize: 5,
        storeOptions: [Object],
        store: [Store],
        host: 'localhost',
        port: 27017,
        options: [Object],
        sessionPool: [ServerSessionPool],
        sessions: [],
        promiseLibrary: [Function: Promise] } },
  cursorState:
   { cursorId: null,
     cmd: { aggregate: 'venuesches', pipeline: [Array], cursor: {} },
     documents: [],
     cursorIndex: 0,
     dead: false,
     killed: false,
     init: false,
     notified: false,
     limit: 0,
     skip: 0,
     batchSize: 1000,
     currentLimit: 0,
     transforms: undefined,
     raw: undefined,
     reconnect: true },
  logger: Logger { className: 'Cursor' },
  _readableState:
   ReadableState {
     objectMode: true,
     highWaterMark: 16,
     buffer: BufferList { head: null, tail: null, length: 0 },
     length: 0,
     pipes: null,
     pipesCount: 0,
     flowing: null,
     ended: false,
     endEmitted: false,
     reading: false,
     sync: true,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     paused: true,
     emitClose: true,
     destroyed: false,
     defaultEncoding: 'utf8',
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null },
  readable: true,
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  s:
   { maxTimeMS: null,
     state: 0,
     streamOptions: {},
     bson: BSON {},
     ns: 'FYP.venuesches',
     cmd: { aggregate: 'venuesches', pipeline: [Array], cursor: {} },
     options:
      { readPreference: null,
        cursor: {},
        promiseLibrary: [Function: Promise],
        cursorFactory: [Function],
        disconnectHandler: [Store],
        topology: [Server] },
     topology:
      Server {
        _events: [Object],
        _eventsCount: 25,
        _maxListeners: Infinity,
        clientInfo: [Object],
        s: [Object] },
     topologyOptions:
      { host: 'localhost',
        port: 27017,
        disconnectHandler: [Store],
        cursorFactory: [Function],
        reconnect: true,
        emitError: true,
        size: 5,
        monitorCommands: false,
        socketTimeout: 360000,
        connectionTimeout: 30000,
        promiseLibrary: [Function: Promise],
        clientInfo: [Object],
        servers: [Array],
        caseTranslate: true,
        useNewUrlParser: true,
        db: 'FYP',
        authSource: 'FYP',
        dbName: 'FYP',
        socketTimeoutMS: 360000,
        connectTimeoutMS: 30000,
        bson: BSON {} },
     promiseLibrary: [Function: Promise],
     session: undefined },
  sortValue: undefined }

我在某处做错了吗?

0 个答案:

没有答案