如何从Mongodb获取数据 [英] How do I get data from Mongodb
本文介绍了如何从Mongodb获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个片段:
const slackProfiles = await Promise.all(
checkinsDetails.map(async ({ employeeEmail }) => {
const employeeData = Employee.findOne({
workEmail: employeeEmail,
});
console.log('employee ', employeeData);
const slackId = employeeData ? employeeData.slackId : '';
当我在控制台中记录员工数据时,我得到了这种数据:
When I log the employee data in my console, I am getting this kind of data:
employee Query {
_mongooseOptions: {},
_transforms: [],
_hooks: Kareem { _pres: Map {}, _posts: Map {} },
_executionCount: 0,
mongooseCollection:
NativeCollection {
collection: null,
opts:
{ bufferCommands: true,
capped: false,
'$wasForceClosed': undefined },
name: 'employees',
collectionName: 'employees',
conn:
NativeConnection {
base: [Mongoose],
collections: [Object],
models: [Object],
config: [Object],
replica: false,
options: null,
otherDbs: [],
relatedDbs: {},
states: [Object],
_readyState: 0,
_closeCalled: false,
_hasOpened: false,
'$internalEmitter': [EventEmitter],
_listening: false },
queue: [],
buffer: true,
emitter:
EventEmitter {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined } },
model:
{ [Function: model]
hooks: Kareem { _pres: [Map], _posts: [Map] },
base:
Mongoose {
connections: [Array],
models: [Object],
modelSchemas: [Object],
options: [Object],
_pluralize: [Function: pluralize],
Schema: [Function],
model: [Function],
plugins: [Array] },
modelName: 'Employee',
...
当我在 EMployee.findOne({})
之前附加 await
时,控制台中没有记录任何内容.我也试过
When I append await
before EMployee.findOne({})
, nothing is logged in the console. I have also tried
Employee.findOne({
workEmail: employeeEmail,
},(err,data)=>console.log("data",data);
但它不输出任何东西.
推荐答案
你应该试试这个,我认为这对你有用.
You should try this , i think this would work for you.
Employee.findOne({workEmail: employeeEmail}).then(err, result) {console.log(result)};
这篇关于如何从Mongodb获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文