在这里处理一个奇怪的问题.这是一个从mongodb中提取并传递给以下函数的对象数组.
我forEach从数据库中拉出的数组中依次尝试了以下3个日志:
e(正确返回的数组中的object元素).如您所见,所有属性(键)都存在:{ paid: false,
hotelWebsite: 'www.testing.com',
_id:5951848a24bb261eed09d638,
hotelAddress: '123 easy street',
...etc }
Run Code Online (Sandbox Code Playgroud)
console.log(Object.keys(e)) 正在回归不是关键的东西......[ '__parentArray',
'__parent',
'__index',
'$__',
'isNew',
'errors',
'_doc',
'$init' ]
Run Code Online (Sandbox Code Playgroud)
for(key in e){
console.log(key);
}
Run Code Online (Sandbox Code Playgroud)
它返回绝对混乱的数据,其中一部分包含对象的实际键:
__parentArray
__parent
__index
$__
isNew
errors
_doc
$init
id
_id
hotelWebsite
hotelAddress
hotelNumber
hotelName
courseCost
courseDate
courseState
courseCity
courseName
paid
studentComments
studentEmail
studentPhone
studentCountry
studentZip
studentState
studentCity
studentAddress
studentCompany
studentName
schema
constructor
$__original_remove
remove
_pres
_posts
$__original_validate
validate
toBSON
markModified
populate
save
update …Run Code Online (Sandbox Code Playgroud) 我在现有模型上运行 .find() 查询。我过去曾使用过此代码并且什么也没改变,但现在突然由于某种原因它不起作用。我在想 MongoDB 或 MongooseJS 已更新并且功能已更改。
var retrieve = function() {
Repo.find({}, function(err, docs) {
console.log(docs)
})
};
retrieve();
Run Code Online (Sandbox Code Playgroud)
返回
[
model {
'$__': InternalCache {
strictMode: true,
selected: {},
shardval: undefined,
saveError: undefined,
validationError: undefined,
adhocPaths: undefined,
removing: undefined,
inserting: undefined,
version: undefined,
getters: {},
_id: 5e02e91c908f0f086e737189,
populate: undefined,
populated: undefined,
wasPopulated: false,
scope: undefined,
activePaths: [StateMachine],
pathsToScopes: {},
ownerDocument: undefined,
fullPath: undefined,
emitter: [EventEmitter],
'$options': true
},
isNew: false,
errors: undefined,
_doc: {
__v: 0,
stars: 2, …Run Code Online (Sandbox Code Playgroud)