例如下面的对象。如果我不想返回整个对象,我只想返回DateInStock,该怎么办?我们如何使用node js在mongo中查询它?
{
"message": "success",
"data": [
{
"_id": "5ddc97ebeefab43ae69c09a3",
"VIN": "1D3HB18T29S817612",
"Body": "Quad Cab Pickup",
"BookValue": "6686",
"DateInStock": "08/01/2019",
"Description": "",
"Doors": 4,
"DriveType": "RWD",
"EngineCylinders": "8",
"EngineDisplacement": "5.7L",
"ExteriorColor": "Deep Water Blue Pearl",...
答案 0 :(得分:1)
您可以将要包含或排除的字段作为第二个参数传递给对象。
值为1的字段将包含该字段,而值为0的字段将排除该字段。
请注意,_id
默认返回,因此如果要排除它,则必须通过_id: 0
db.yourColletion.find({ _id: "5ddc97ebeefab43ae69c09a3" }, { "DateInStock": 1 })