MongoDB .find() 没有 return 正确的数据
MongoDB .find() doesn't return the right data
我正在尝试从 mongodb 获取数据,但每当我尝试使用 find()
时,我都会收到以下响应。我是 Mongo 的新手,只是不知道为什么会这样。此代码也是用 TypeScript 编写的,用于编写 Discord 机器人。
Query {
_mongooseOptions: {},
_transforms: [],
_hooks: Kareem { _pres: Map(0) {}, _posts: Map(0) {} },
_executionStack: null,
mongooseCollection: Collection {
collection: null,
Promise: [Function: Promise],
modelName: 'verifiedUsers',
_closed: false,
opts: {
autoIndex: true,
autoCreate: true,
schemaUserProvidedOptions: {},
capped: false,
Promise: [Function: Promise],
'$wasForceClosed': undefined
},
name: 'verifiedUsers',
collectionName: 'verifiedUsers',
conn: NativeConnection {
base: [Mongoose],
collections: [Object],
models: [Object],
config: {},
replica: false,
options: null,
otherDbs: [],
relatedDbs: {},
states: [Object: null prototype],
_readyState: 0,
_closeCalled: false,
_hasOpened: false,
plugins: [],
id: 0,
_queue: [],
_listening: false
},
queue: [],
buffer: true,
emitter: EventEmitter {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false
}
},
model: Model { verifiedUsers },
schema: Schema {
obj: { ign: [Object], memberid: [Object] },
paths: {
ign: [SchemaString],
memberid: [SchemaString],
_id: [ObjectId],
__v: [SchemaNumber]
},
aliases: {},
subpaths: {},
virtuals: { id: [VirtualType] },
singleNestedPaths: {},
nested: {},
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
methodOptions: {},
statics: {},
tree: {
ign: [Object],
memberid: [Object],
_id: [Object],
__v: [Function: Number],
id: [VirtualType]
},
query: {},
childSchemas: [],
plugins: [ [Object], [Object], [Object], [Object], [Object] ],
'$id': 1,
mapPaths: [],
s: { hooks: [Kareem] },
_userProvidedOptions: {},
options: {
typeKey: 'type',
id: true,
_id: true,
validateBeforeSave: true,
read: null,
shardKey: null,
discriminatorKey: '__t',
autoIndex: null,
minimize: true,
optimisticConcurrency: false,
versionKey: '__v',
capped: false,
bufferCommands: true,
strictQuery: true,
strict: true,
pluralization: true
},
'$globalPluginsApplied': true
},
op: 'find',
options: {},
_conditions: {},
_fields: undefined,
_update: undefined,
_path: undefined,
_distinct: undefined,
_collection: NodeCollection {
collection: Collection {
collection: null,
这是我使用的代码:
架构:
import mongoose from 'mongoose'
const verifiedUsers = new mongoose.Schema({
ign: {
type: String,
required: true
},
memberid: {
type: String,
required: true
},
})
export default mongoose.model('verifiedUsers', verifiedUsers, 'verifiedUsers')
获取验证用户:
import mongoose from 'mongoose'
import verifiedUsers from './schemas/verified-users'
client.on('ready', async () => {
await mongoose.connect(
process.env.mongo_uri || '',
{
keepAlive: true
})
})
async function getVerifiedUsers() {
console.log(verifiedUsers.find())
}
getVerifiedUsers()
为什么会发生这种情况,我该如何预防?
看来你需要打电话给.exec()
。
勾选Model.find() and 。
也许其他人可以解释为什么决定这样做而不是等待 .find()
获取数据。
我正在尝试从 mongodb 获取数据,但每当我尝试使用 find()
时,我都会收到以下响应。我是 Mongo 的新手,只是不知道为什么会这样。此代码也是用 TypeScript 编写的,用于编写 Discord 机器人。
Query {
_mongooseOptions: {},
_transforms: [],
_hooks: Kareem { _pres: Map(0) {}, _posts: Map(0) {} },
_executionStack: null,
mongooseCollection: Collection {
collection: null,
Promise: [Function: Promise],
modelName: 'verifiedUsers',
_closed: false,
opts: {
autoIndex: true,
autoCreate: true,
schemaUserProvidedOptions: {},
capped: false,
Promise: [Function: Promise],
'$wasForceClosed': undefined
},
name: 'verifiedUsers',
collectionName: 'verifiedUsers',
conn: NativeConnection {
base: [Mongoose],
collections: [Object],
models: [Object],
config: {},
replica: false,
options: null,
otherDbs: [],
relatedDbs: {},
states: [Object: null prototype],
_readyState: 0,
_closeCalled: false,
_hasOpened: false,
plugins: [],
id: 0,
_queue: [],
_listening: false
},
queue: [],
buffer: true,
emitter: EventEmitter {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false
}
},
model: Model { verifiedUsers },
schema: Schema {
obj: { ign: [Object], memberid: [Object] },
paths: {
ign: [SchemaString],
memberid: [SchemaString],
_id: [ObjectId],
__v: [SchemaNumber]
},
aliases: {},
subpaths: {},
virtuals: { id: [VirtualType] },
singleNestedPaths: {},
nested: {},
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
methodOptions: {},
statics: {},
tree: {
ign: [Object],
memberid: [Object],
_id: [Object],
__v: [Function: Number],
id: [VirtualType]
},
query: {},
childSchemas: [],
plugins: [ [Object], [Object], [Object], [Object], [Object] ],
'$id': 1,
mapPaths: [],
s: { hooks: [Kareem] },
_userProvidedOptions: {},
options: {
typeKey: 'type',
id: true,
_id: true,
validateBeforeSave: true,
read: null,
shardKey: null,
discriminatorKey: '__t',
autoIndex: null,
minimize: true,
optimisticConcurrency: false,
versionKey: '__v',
capped: false,
bufferCommands: true,
strictQuery: true,
strict: true,
pluralization: true
},
'$globalPluginsApplied': true
},
op: 'find',
options: {},
_conditions: {},
_fields: undefined,
_update: undefined,
_path: undefined,
_distinct: undefined,
_collection: NodeCollection {
collection: Collection {
collection: null,
这是我使用的代码: 架构:
import mongoose from 'mongoose'
const verifiedUsers = new mongoose.Schema({
ign: {
type: String,
required: true
},
memberid: {
type: String,
required: true
},
})
export default mongoose.model('verifiedUsers', verifiedUsers, 'verifiedUsers')
获取验证用户:
import mongoose from 'mongoose'
import verifiedUsers from './schemas/verified-users'
client.on('ready', async () => {
await mongoose.connect(
process.env.mongo_uri || '',
{
keepAlive: true
})
})
async function getVerifiedUsers() {
console.log(verifiedUsers.find())
}
getVerifiedUsers()
为什么会发生这种情况,我该如何预防?
看来你需要打电话给.exec()
。
勾选Model.find() and
也许其他人可以解释为什么决定这样做而不是等待 .find()
获取数据。