我想将Model.find();
查询返回的对象存储在变量中,以便可以使用该对象的属性作为条件输入另一个Model.findOneAndUpdate();
查询中。
类似
var userobject = User.find({ username: theidiwanttosearch }, function (err, returneduser) {
if (err) { console.log(err) }
else return returneduser;
});
然后做类似的事情。
User.findOneAndUpdate({ username: user }, { $set: { "notification.counter": userobject.apropertyoftheobject + 1 } },...
但是当我在创建console.log(userobject)之后立即获得结果
Query {
_mongooseOptions: {},
mongooseCollection:
NativeCollection {
collection: Collection { s: [Object] },
opts:
{ bufferCommands: true,
capped: false,
'$wasForceClosed': undefined },
name: 'users',
collectionName: 'users',
conn:
NativeConnection {
base: [Object],
collections: [Object],
models: [Object],
config: [Object],
replica: false,
options: null,
otherDbs: [],
relatedDbs: {},
states: [Object],
_readyState: 1,
_closeCalled: false,
_hasOpened: true,
_listening: false,
_connectionOptions: [Object],
name: 'MPdb',
host: 'localhost',
port: 27017,
user: null,
pass: null,
client: [Object],
'$initialConnection': [Object],
_events: [Object],
_eventsCount: 1,
db: [Object] },
queue: [],
buffer: false,
emitter:
EventEmitter {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined } },
model:
{ [Function: model]
hooks: Kareem { _pres: [Object], _posts: [Object] },
base:
Mongoose {
connections: [Object],
models: [Object],
modelSchemas: [Object],
options: [Object],
_pluralize: [Function: pluralize],
plugins: [Object] },
modelName: 'User',
model: [Function: model],
db:
NativeConnection {
base: [Object],
collections: [Object],
models: [Object],
config: [Object],
replica: false,
options: null,
otherDbs: [],
relatedDbs: {},
states: [Object],
_readyState: 1,
_closeCalled: false,
_hasOpened: true,
_listening: false,
_connectionOptions: [Object],
name: 'MPdb',
host: 'localhost',
port: 27017,
user: null,
pass: null,
client: [Object],
'$initialConnection': [Object],
_events: [Object],
_eventsCount: 1,
db: [Object] },
discriminators: undefined,
'$appliedMethods': true,
'$appliedHooks': true,
schema:
Schema {
obj: [Object],
paths: [Object],
aliases: {},
subpaths: {},
virtuals: [Object],
singleNestedPaths: {},
nested: [Object],
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
methodOptions: {},
statics: {},
tree: [Object],
query: {},
childSchemas: [Object],
plugins: [Object],
s: [Object],
_userProvidedOptions: {},
options: [Object],
'$globalPluginsApplied': true },
collection:
NativeCollection {
collection: [Object],
opts: [Object],
name: 'users',
collectionName: 'users',
conn: [Object],
queue: [],
buffer: false,
emitter: [Object] },
Query: { [Function] base: [Object] },
'$__insertMany': [Function],
'$init': Promise { null },
'$caught': true },
schema:
Schema {
obj:
{ username: [Function: String],
email: [Function: String],
password: [Function: String],
company: [Function: String],
contact: [Function: Number],
country: [Function: String],
isLoggedIn: [Function: Boolean],
createdOn: [Object],
ads: [Object],
notification: [Object] },
paths:
{ username: [Object],
email: [Object],
password: [Object],
company: [Object],
contact: [Object],
country: [Object],
isLoggedIn: [Object],
createdOn: [Object],
ads: [Object],
'notification.counter': [Object],
'notification.notidata': [Object],
_id: [Object],
__v: [Object] },
aliases: {},
subpaths: {},
virtuals: { id: [Object] },
singleNestedPaths: {},
nested: { notification: true },
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
methodOptions: {},
statics: {},
tree:
{ username: [Function: String],
email: [Function: String],
password: [Function: String],
company: [Function: String],
contact: [Function: Number],
country: [Function: String],
isLoggedIn: [Function: Boolean],
createdOn: [Object],
ads: [Object],
notification: [Object],
_id: [Object],
__v: [Function: Number],
id: [Object] },
query: {},
childSchemas: [ [Object] ],
plugins: [ [Object], [Object], [Object], [Object], [Object] ],
s: { hooks: [Object] },
_userProvidedOptions: {},
options:
{ typeKey: 'type',
id: true,
noVirtualId: false,
_id: true,
noId: false,
validateBeforeSave: true,
read: null,
shardKey: null,
autoIndex: null,
minimize: true,
discriminatorKey: '__t',
versionKey: '__v',
capped: false,
bufferCommands: true,
strict: true,
pluralization: true },
'$globalPluginsApplied': true },
op: 'find',
options: {},
_conditions: { username: 'mesam' },
_fields: undefined,
_update: undefined,
_path: undefined,
_distinct: undefined,
_collection:
NodeCollection {
collection:
NativeCollection {
collection: [Object],
opts: [Object],
name: 'users',
collectionName: 'users',
conn: [Object],
queue: [],
buffer: false,
emitter: [Object] },
collectionName: 'users' },
_traceFunction: undefined,
'$useProjection': true }
我希望userobject向我展示从User.find查询返回的对象,为什么在输出中显示所有这些内容?