Express / MongoDb 按 ID 查找所有对象并将它们保存到数组中
Posted
技术标签:
??????Express / MongoDb ? ID ??????????????????????:Express / MongoDb find all objects by ID and save them to an array ??????:2019-03-25 23:43:07 ??????:??monongodb??????:
let statSchema = new mongoose.Schema(
title: String,
statId: String,
stats:
likeCount: Number,
commentCount: Number
);
let MyStat = mongoose.model("MyStat", statSchema);
??????????????????statId
???????????????
??????request
(npm ??)?????,??????statId
?? API ?? JSON,? API ??????? statId
???? stats
(likeCount ? commentCount) .
??????????:
MyStat.find(, function(err, foundStats)
if (err) throw err;
console.log(foundStats);
);
??????????????,??????????“statId”?
?????console.log(foundStats.linkId);
,????undefined
?
??????:
Mongoose, Select a specific field with find????? ?????1?:?? statId ???“_id”????????????? id ??,??? id ???? '_id' ????
??????,?????
MyStat.find(, '_id', function(err, foundStats)
if (err) throw err;
console.log(foundStats);
);
?“foundStats”?,??????????? id?
???????mongoose?mongoDB
????:
?????2?:foundStats ???????????????
foundStats.forEach((element) =>
console.log(element.statId);
);
?????? statId,???????:
MyStat.find(, 'statId' , function(err, foundStats)
if (err) throw err;
console.log(foundStats);
);
?????here
????:
以上是关于Express / MongoDb 按 ID 查找所有对象并将它们保存到数组中的主要内容,如果未能解决你的问题,请参考以下文章
GORM 在 Grails 中使用 MongoDB 按 ID 获取/查找资源
按 ID 查找在 Nodejs MongoDB 中不起作用 [重复]