Answer the question
In order to leave comments, you need to log in
How to filter query result from Mongoose?
Using Mongoose with find({}) I get all the documents, but when iterating in a loop, there are a lot of auxiliary things (I looked, outputting to the console), but I need ONLY the fields.
Is there a way to filter?
At:
User.find({}, function(err, docs){
for(let key in docs) {
console.log(docs[key]);
}
});
docs[key]
:{ status: 'active',
ID: '2',
_id: 5877e9f30d64858af7b3dd6c }
{ [Function] numAsyncPres: 1 }
[Function: wrappedPointCut]
{ '$__original_save':
[ { [Function: fn] isAsync: false },
{ [Function: fn] isAsync: true } ],
'$__original_validate': [ { [Function: fn] isAsync: true } ],
'$__original_remove': [ { [Function: fn] isAsync: true } ] }
{ '$__original_save': [],
'$__original_validate': [],
'$__original_remove': [] }
{ [Function] numAsyncPres: 1 }
[Function: wrappedPointCut]
{ [Function] numAsyncPres: 1 }
[Function: wrappedPointCut]
NativeConnection {
base:
Mongoose {
connections: [ [Object], [Object], [Object], [Object], [Circular] ],
plugins: [],
models: {},
modelSchemas: { User: [Object], Patient: [Object] },
options: { pluralization: true } },
collections:
{ users:
NativeCollection {
collection: [Object],
opts: [Object],
name: 'users',
collectionName: 'users',
conn: [Circular],
queue: [],
buffer: false,
emitter: [Object] } },
models:
{ User:
{ [Function: model]
hooks: [Object],
base: [Object],
modelName: 'User',
model: [Function: model],
db: [Circular],
discriminators: undefined,
schema: [Object],
collection: [Object],
Query: [Object],
'$__insertMany': [Function],
insertMany: [Function] } },
config: { autoIndex: true },
{ status: 'active',
ID: '2',
_id: 5877e9f30d64858af7b3dd6c }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question