MongoDB 中有一个集合,例如:
{
"_id" : ObjectId("5bcc4c7d1e2c701be024de99"),
"className" : "Class 10",
"gradeLevel" : "10th",
"subjectName" : "Math",
"teacherId" : "abcd@gmail.com",
"__v" : 0
},
{
"_id" : ObjectId("5bd45277f5b9430013f4a604"),
"className" : "Class 11",
"gradeLevel" : "11th",
"subjectName" : "Maths",
"teacherId" : "abcd@gmail.com",
"__v" : 0
},
{
"_id" : ObjectId("5bd470fe452cb33af4b8407a"),
"className" : "Class 10",
"gradeLevel" : "12th",
"subjectName" : "Math",
"teacherId" : "abcd@gmail.com",
"__v" : 0
},
现在我想获取那些值为 of_id 的文档:ObjectId(“5bd45277f5b9430013f4a604”),ObjectId(“5bd470fe452cb33af4b8407a”)。
我正在使用 Mongoose 和node.js。所以请告诉我有什么办法可以做到这一点。
Model.find({ _id: { $in: ['5bd45277f5b9430013f4a604', '5bd470fe452cb33af4b8407a'] } })
.then(docs => console.log(docs))
.catch(err => console.log(err));
我是一名优秀的程序员,十分优秀!