我的一些文档中有一个这样的额外"Game"
字段
{
"_id" : NumberLong(204648),
"loc" : [
-41.2887953,
174.7772114
],
"ts" : "2020-09-11T02:54:11Z",
"v" : 52,
"game": 2, <--------
}
我想返回这些在"Game"
字段中具有任何值的文档。
mongoose.connection.db.collection('games').find({ "game": {} }, (err, docs) => {
console.log(docs);
});
我试过了。但是,它只是返回undefined
。我如何只用console.log记录具有该"game"
字段值的文档?
const a = await mongoose.connection.db.collection('game').find({ game: { $exists: true } });
console.log(a);
退货
Cursor {
_readableState: ReadableState {
objectMode: true,
highWaterMark: 16,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
destroyed: false,
errored: null,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
decoder: null,
encoding: null,
[Symbol(kPaused)]: null
},
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
operation: FindOperation {
options: {
skip: 0,
limit: 0,
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: [ReadPreference],
db: [Db],
promiseLibrary: [Function: Promise]
},
ns: MongoDBNamespace { db: 'db', collection: 'game' },
cmd: {
find: 'db.game',
limit: 0,
skip: 0,
query: [Object],
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: [ReadPreference]
},
readPreference: ReadPreference {
mode: 'primary',
tags: undefined,
hedge: undefined
},
cursorState: {
cursorId: null,
cmd: [Object],
documents: [],
cursorIndex: 0,
dead: false,
killed: false,
init: false,
notified: false,
limit: 0,
skip: 0,
batchSize: 1000,
currentLimit: 0,
transforms: undefined,
raw: undefined
}
},
pool: null,
server: null,
disconnectHandler: undefined,
bson: BSON {},
ns: 'db.game',
namespace: MongoDBNamespace { db: 'db', collection: 'game' },
cmd: {
find: 'db.game',
limit: 0,
skip: 0,
query: { tg: [Object] },
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: ReadPreference {
mode: 'primary',
tags: undefined,
hedge: undefined
}
},
options: {
skip: 0,
limit: 0,
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: ReadPreference {
mode: 'primary',
tags: undefined,
hedge: undefined
},
db: Db {
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
s: [Object],
serverConfig: [Getter],
bufferMaxEntries: [Getter],
databaseName: [Getter],
[Symbol(kCapture)]: false
},
promiseLibrary: [Function: Promise]
},
topology: NativeTopology {
_events: [Object: null prototype] {
authenticated: [Function (anonymous)],
error: [Array],
timeout: [Array],
close: [Array],
parseError: [Array],
fullsetup: [Array],
all: [Array],
reconnect: [Array],
commandStarted: [Function (anonymous)],
commandSucceeded: [Function (anonymous)],
commandFailed: [Function (anonymous)],
serverOpening: [Function (anonymous)],
serverClosed: [Function (anonymous)],
serverDescriptionChanged: [Function (anonymous)],
serverHeartbeatStarted: [Function (anonymous)],
serverHeartbeatSucceeded: [Array],
serverHeartbeatFailed: [Function (anonymous)],
topologyOpening: [Function (anonymous)],
topologyClosed: [Function (anonymous)],
topologyDescriptionChanged: [Function (anonymous)],
joined: [Array],
left: [Function (anonymous)],
ping: [Function (anonymous)],
ha: [Function (anonymous)],
connectionPoolCreated: [Function (anonymous)],
connectionPoolClosed: [Function (anonymous)],
connectionCreated: [Function (anonymous)],
connectionReady: [Function (anonymous)],
connectionClosed: [Function (anonymous)],
connectionCheckOutStarted: [Function (anonymous)],
connectionCheckOutFailed: [Function (anonymous)],
connectionCheckedOut: [Function (anonymous)],
connectionCheckedIn: [Function (anonymous)],
connectionPoolCleared: [Function (anonymous)],
open: [Function],
reconnectFailed: [Function (anonymous)]
},
_eventsCount: 36,
_maxListeners: Infinity,
s: {
id: 0,
options: [Object],
seedlist: [Array],
state: 'connected',
description: [TopologyDescription],
serverSelectionTimeoutMS: 30000,
heartbeatFrequencyMS: 10000,
minHeartbeatFrequencyMS: 500,
Cursor: [class Cursor extends CoreCursor],
bson: BSON {},
servers: [Map],
sessionPool: [ServerSessionPool],
sessions: Set(0) {},
promiseLibrary: [Function: Promise],
credentials: undefined,
clusterTime: null,
connectionTimers: Set(0) {},
sCapabilities: [ServerCapabilities]
},
[Symbol(kCapture)]: false,
[Symbol(waitQueue)]: Denque {
_head: 2,
_tail: 2,
_capacity: undefined,
_capacityMask: 3,
_list: [Array]
}
},
cursorState: {
cursorId: null,
cmd: {
find: 'db.game',
limit: 0,
skip: 0,
query: [Object],
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: [ReadPreference]
},
documents: [],
cursorIndex: 0,
dead: false,
killed: false,
init: false,
notified: false,
limit: 0,
skip: 0,
batchSize: 1000,
currentLimit: 0,
transforms: undefined,
raw: undefined
},
logger: Logger { className: 'Cursor' },
s: {
numberOfRetries: 5,
tailableRetryInterval: 500,
currentNumberOfRetries: 5,
state: 0,
promiseLibrary: [Function: Promise],
explicitlyIgnoreSession: false
},
[Symbol(kCapture)]: false
}
我没有得到任何文件console.log,只是这个Cursor返回。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句