Z
Z
zelenovqq2020-10-14 16:48:16
MongoDB
zelenovqq, 2020-10-14 16:48:16

How to get only 1 value with .find in mongodb?

here is the code:

first I create an account in the database

await mongo().then(async (mongoose) => {
try {
await setSchema.insertMany( [
{ "account": account }
]);
} finally {
mongoose.connection.close()
}
})

output it

const result = await setSchema.find().limit(1);

console.log(result) outputs

:

{ _id: '5f86fbdb28740118a4dea921', account: '545:545', __v: 0 }

how to remove __v and _id ?
i.e. should be
account: '545:545'
or
545:545

Please help urgently!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2020-10-14
@yarkov

https://docs.mongodb.com/manual/tutorial/project-f...

const result = await setSchema.find({}, {account: 1}).limit(1);

W
WbICHA, 2020-10-14
@WblCHA

Open mongus documentation?
https://mongoosejs.com/docs/api.html#model_Model.f...
Upd.
And documentation of objects?
https://developer.mozilla.org/en/docs/Web/JavaScript...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question