Javascript 我只希望console.log()我的数据存在于我的MongoDB数据库中
我正在mongodb中的数据库中输入数据,并希望console.log()输入的数据,但每当我尝试这样做时,我的数据都会进入console,但带有各种其他属性,我不需要这些属性。 我只想把输入的数据带到我的控制台上Javascript 我只希望console.log()我的数据存在于我的MongoDB数据库中,javascript,node.js,mongodb,mongoose-schema,console.log,Javascript,Node.js,Mongodb,Mongoose Schema,Console.log,我正在mongodb中的数据库中输入数据,并希望console.log()输入的数据,但每当我尝试这样做时,我的数据都会进入console,但带有各种其他属性,我不需要这些属性。 我只想把输入的数据带到我的控制台上 const mongoose = require("mongoose"); mongoose .connect("mongodb://localhost/playground") .then(() => { console.log("database conn
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();
我希望在控制台上显示的是(mongo数据库中的实际数据)
但我得到的是我的数据,但有了这些额外的信息:-
[
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我的类时,我不希望这些额外的信息和我的数据一起出现 我明白问题所在。我正在运行mongoose 5.0.1,刚刚更新了mongoose包,它停止显示其他属性 我明白问题所在。我正在运行mongoose 5.0.1,刚刚更新了mongoose包,它停止显示其他属性
[
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
}
]