【发布时间】:2023-03-06 19:42:02
【问题描述】:
我们如何查询匹配的值,并返回它的键。在这种情况下,数据库中只有 1 个文档。
const mongoose = require("mongoose");
const listSchema = new mongoose.Schema({
yuck: [String],
yumm: [String]
});
const List = mongoose.model("List", listSchema);
List.create({
yuck: [ "orange", "banana"],
yumm: ["broccoli", "chocolate"]
});
List.find({ $query: "chocolate" }, (err,result)=>{
console.log("Key is>>>", result);
});
//How do we query such that it will return the key whose value matches?
// Key is>>> yumm
【问题讨论】:
-
我更新我的答案