Я ввожу данные в свою базу данных в mongodb и хочу console.log () ввести эти данные, но всякий раз, когда я пытаюсь это сделать, мои данные поступают на консоль, но с различными другими свойствами, которые мне не нужны. Я просто хочу перенести данные, введенные на моей консоли!
const mongoose = require("mongoose");
mongoose
.connect("mongodb://localhost/playground")
.then(() => {
console.log("database connected");
})
.catch(err => {
console.log("Could not connect", err);
});
const courseSchema = new mongoose.Schema({
name: String,
author: String,
tags: [String],
date: { type: Date, default: Date.now },
isPublished: Boolean
});
// To Create a class of Course, we need to use the model method
const Course = mongoose.model("Course", courseSchema);
async function createCourse() {
//Lets create a object to the Course class
// Async Routine
const course = new Course({
name: "React Course",
author: "Mosh",
tags: ["FrontEnd", "React"],
isPublished: true
});
// Log Tree : Schema -> Model -> Class -> Object !....
const result = await course.save();
console.log(result);
}
async function getCourse() {
const course = await Course.find();
//Bringing the data from the data base.
console.log(course);
}
getCourse();
То, что я хочу отобразить на моей консоли, - (Фактические данные в моей базе данных mon go)
[ {"_id":{"$oid":"5e847c6e6ed0fa2c785647e4"},
"tags":["Backend","Node"],
"date":{"$date":{"$numberLong":"1585740910542"}},
"name":"Node Course",
"author":"Mosh","isPublished":true,
"__v":{"$numberInt":"0"}
} ,
{"_id":{"$oid":"5e84868970369f3a30e25270"},
"tags":["FrontEnd","React"],
"date":{"$date":{"$numberLong":"1585743497438"}},
"name":"React Course",
"author":"Mosh",
"isPublished":true,"__v":{"$numberInt":"0"} } ]
НО То, что я получаю, это мои данные НО с этой дополнительной информацией: -
[
model {
'$__': InternalCache {
strictMode: true,
selected: {},
shardval: undefined,
saveError: undefined,
validationError: undefined,
adhocPaths: undefined,
removing: undefined,
inserting: undefined,
version: undefined,
getters: {},
_id: 5e847c6e6ed0fa2c785647e4,
populate: undefined,
populated: undefined,
wasPopulated: false,
scope: undefined,
activePaths: [StateMachine],
pathsToScopes: {},
ownerDocument: undefined,
fullPath: undefined,
emitter: [EventEmitter],
'$options': true
},
isNew: false,
errors: undefined,
_doc: {
tags: [Array],
date: 2020-04-01T11:35:10.542Z,
_id: 5e847c6e6ed0fa2c785647e4,
name: 'Node Course',
author: 'Mosh',
isPublished: true,
__v: 0
},
'$init': true
},
model {
'$__': InternalCache {
strictMode: true,
selected: {},
shardval: undefined,
saveError: undefined,
validationError: undefined,
adhocPaths: undefined,
removing: undefined,
inserting: undefined,
version: undefined,
getters: {},
_id: 5e84868970369f3a30e25270,
populate: undefined,
populated: undefined,
wasPopulated: false,
scope: undefined,
activePaths: [StateMachine],
pathsToScopes: {},
ownerDocument: undefined,
fullPath: undefined,
emitter: [EventEmitter],
'$options': true
},
isNew: false,
errors: undefined,
_doc: {
tags: [Array],
_id: 5e84868970369f3a30e25270,
name: 'React Course',
isPublished: true,
__v: 0
},
'$init': true
}
]
Я не хочу получать эту дополнительную информацию вместе с моими данными, когда я console.log своего Класса!