我们可以在ObjectId内添加一个变量而不是字符串吗???示例const _id = ObjectId(variable);
或类似:
让变量='5defabcty1234ds';
{'$ match':{_id:mongoose.Types.ObjectId(variable)}},
是,它将根据字符串创建ObjectID,请参见文档:https://docs.mongodb.com/manual/reference/method/ObjectId/#specify-a-hexadecimal-string