Когда я печатаю
let app = express ()
на консоли, он печатается следующим образом.
{ [EventEmitter: app]
_events: { mount: [Function: onmount] },
_eventsCount: 1,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function: emit],
addListener: [Function: addListener],
on: [Function: addListener],
prependListener: [Function: prependListener],
once: [Function: once],
...
}
Внутри фрагмента кода, есть on: function и т. д. ... так что я думаю, что это дает мне возможность использовать функцию на этом app.on (...)
const Grid = require('gridfs-stream');
let gfs;
conn.once('open', () => {
// Init stream
gfs = Grid(conn.db, mongoose.mongo);
gfs.collection('uploads');
console.log(gfs);
});
Но, когда я печатаю объект gfs наконсоль это печатает это.Вот мой пример ссылки: https://github.com/qkreltms/mongodb_simple_file_upload_to_db_example/blob/master/app.js
Grid {
db:
Db {
_events:
{ reconnect: [Function], close: [Function], timeout: [Function] },
_eventsCount: 3,
_maxListeners: undefined,
s:
{ databaseName: 'imgSaveTest',
dbCache: {},
children: [],
topology: [Server],
options: [Object],
logger: [Logger],
bson: BSON {},
readPreference: [ReadPreference],
bufferMaxEntries: -1,
parentDb: null,
pkFactory: undefined,
nativeParser: undefined,
promiseLibrary: [Function: Promise],
noListener: false,
readConcern: undefined },
serverConfig: [Getter],
bufferMaxEntries: [Getter],
databaseName: [Getter] },
mongo:
{ [Function]
MongoError: [Function: MongoError],
MongoNetworkError: [Function: MongoNetworkError],
Admin: [Function: Admin],
MongoClient:
{ [Function: MongoClient] super_: [Function], connect: [Circular] },
Db:
{ [Function: Db]
super_: [Function],
SYSTEM_NAMESPACE_COLLECTION: 'system.namespaces',
SYSTEM_INDEX_COLLECTION: 'system.indexes',
SYSTEM_PROFILE_COLLECTION: 'system.profile',
SYSTEM_USER_COLLECTION: 'system.users',
SYSTEM_COMMAND_COLLECTION: '$cmd',
SYSTEM_JS_COLLECTION: 'system.js' },
Collection: [Function: Collection],
Server: [Function: Server],
ReplSet: [Function: ReplSet],
Mongos: [Function: Mongos],
ReadPreference:
{ [Function: ReadPreference]
PRIMARY: 'primary',
PRIMARY_PREFERRED: 'primaryPreferred',
SECONDARY: 'secondary',
SECONDARY_PREFERRED: 'secondaryPreferred',
NEAREST: 'nearest',
isValid: [Function],
primary: [ReadPreference],
primaryPreferred: [ReadPreference],
secondary: [ReadPreference],
secondaryPreferred: [ReadPreference],
nearest: [ReadPreference] },
GridStore:
{ [Function: GridStore]
DEFAULT_ROOT_COLLECTION: 'fs',
DEFAULT_CONTENT_TYPE: 'binary/octet-stream',
IO_SEEK_SET: 0,
IO_SEEK_CUR: 1,
IO_SEEK_END: 2,
exist: [Function],
list: [Function],
read: [Function],
readlines: [Function],
unlink: [Function] },
Chunk: { [Function: Chunk] DEFAULT_CHUNK_SIZE: 261120 },
Logger:
{ [Function: Logger]
reset: [Function],
currentLogger: [Function],
setCurrentLogger: [Function],
filter: [Function],
setLevel: [Function] },
AggregationCursor:
{ [Function: AggregationCursor] super_: [Function], INIT: 0, OPEN: 1, CLOSED: 2 },
CommandCursor:
{ [Function: CommandCursor] super_: [Function], INIT: 0, OPEN: 1, CLOSED: 2 },
Cursor:
{ [Function: Cursor] super_: [Function], INIT: 0, OPEN: 1, CLOSED: 2, GET_MORE: 3 },
GridFSBucket: { [Function: GridFSBucket] super_: [Function] },
CoreServer:
{ [Function: Server]
super_: [Function],
enableServerAccounting: [Function],
disableServerAccounting: [Function],
servers: [Function] },
CoreConnection:
{ [Function: Connection]
super_: [Function],
enableConnectionAccounting: [Function],
disableConnectionAccounting: [Function],
connections: [Function] },
Binary:
{ [Function: Binary]
BUFFER_SIZE: 256,
SUBTYPE_DEFAULT: 0,
SUBTYPE_FUNCTION: 1,
SUBTYPE_BYTE_ARRAY: 2,
SUBTYPE_UUID_OLD: 3,
SUBTYPE_UUID: 4,
SUBTYPE_MD5: 5,
SUBTYPE_USER_DEFINED: 128,
Binary: [Circular] },
Code: { [Function: Code] Code: [Circular] },
Map: { [Function: Map] Map: [Circular] },
DBRef: { [Function: DBRef] DBRef: [Circular] },
Double: { [Function: Double] Double: [Circular] },
Int32: { [Function: Int32] Int32: [Circular] },
Long:
{ [Function: Long]
fromInt: [Function],
fromNumber: [Function],
fromBits: [Function],
fromString: [Function],
INT_CACHE_: [Object],
TWO_PWR_16_DBL_: 65536,
TWO_PWR_24_DBL_: 16777216,
TWO_PWR_32_DBL_: 4294967296,
TWO_PWR_31_DBL_: 2147483648,
TWO_PWR_48_DBL_: 281474976710656,
TWO_PWR_64_DBL_: 18446744073709552000,
TWO_PWR_63_DBL_: 9223372036854776000,
ZERO: [Long],
ONE: [Long],
NEG_ONE: [Long],
MAX_VALUE: [Long],
MIN_VALUE: [Long],
TWO_PWR_24_: [Long],
Long: [Circular] },
MinKey: { [Function: MinKey] MinKey: [Circular] },
MaxKey: { [Function: MaxKey] MaxKey: [Circular] },
ObjectID:
{ [Function: ObjectID]
index: 4899462,
createPk: [Function: createPk],
createFromTime: [Function: createFromTime],
createFromHexString: [Function: createFromHexString],
isValid: [Function: isValid],
ObjectID: [Circular],
ObjectId: [Circular] },
ObjectId:
{ [Function: ObjectID]
index: 4899462,
createPk: [Function: createPk],
createFromTime: [Function: createFromTime],
createFromHexString: [Function: createFromHexString],
isValid: [Function: isValid],
ObjectID: [Circular],
ObjectId: [Circular] },
Symbol: { [Function: Symbol] Symbol: [Circular] },
Timestamp:
{ [Function: Timestamp]
fromInt: [Function],
fromNumber: [Function],
fromBits: [Function],
fromString: [Function],
INT_CACHE_: [Object],
TWO_PWR_16_DBL_: 65536,
TWO_PWR_24_DBL_: 16777216,
TWO_PWR_32_DBL_: 4294967296,
TWO_PWR_31_DBL_: 2147483648,
TWO_PWR_48_DBL_: 281474976710656,
TWO_PWR_64_DBL_: 18446744073709552000,
TWO_PWR_63_DBL_: 9223372036854776000,
ZERO: [Timestamp],
ONE: [Timestamp],
NEG_ONE: [Timestamp],
MAX_VALUE: [Timestamp],
MIN_VALUE: [Timestamp],
TWO_PWR_24_: [Timestamp],
Timestamp: [Circular] },
BSONRegExp: { [Function: BSONRegExp] BSONRegExp: [Circular] },
Decimal128:
{ [Function: Decimal128] fromString: [Function], Decimal128: [Circular] },
connect: [Circular],
instrument: [Function] },
curCol: 'uploads',
_col:
Collection {
s:
{ pkFactory: [Function],
db: [Db],
topology: [Server],
dbName: 'imgSaveTest',
options: [Object],
namespace: 'imgSaveTest.uploads.files',
readPreference: [ReadPreference],
slaveOk: true,
serializeFunctions: undefined,
raw: undefined,
promoteLongs: undefined,
promoteValues: undefined,
promoteBuffers: undefined,
internalHint: null,
collectionHint: null,
name: 'uploads.files',
promiseLibrary: [Function: Promise],
readConcern: undefined,
writeConcern: undefined } } }
gfs.collection ('uploads');
Вы можете видеть, что внутри него нет функции сбора, но он работает, даже если он не существует на консоли.Итак, вопрос в том, откуда берется функция сбора?
Спасибо.