我只想获取流动资产记录。但是它显示了0条记录,请帮助我这条查询中所缺少的内容。如何仅查找相关数据,而不是所有资产。我尝试了很多,但没有成功。
任何人都可以帮助我,我非常感谢
export function assetswisetracking(req, res) {
return Campaign.find(
{"assets._Id": req.params.id }, // <= query part
{assets:{$elemMatch:{"assets._Id": req.params.id}}}
)
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
{
"_id" : ObjectId("5b49d08db8695590d4ea7204"),
"company_id" : ObjectId("59e07c60bdd6d7a454a89304"),
"brand_id" : ObjectId("59e090a8bdd6d7a454a89305"),
"campaign_name" : "testing campaign 1",
"no_of_days" : "7",
"status" : "Executed",
"updated_date" : ISODate("2018-07-14T10:29:33.164Z"),
"created_date" : ISODate("2018-07-14T10:29:33.164Z"),
"active" : true,
"assets" : [
{
"_id" : ObjectId("5b49cef1b8695590d4ea7203"),
"brand_id" : ObjectId("59e090a8bdd6d7a454a89305"),
"medium" : "Billboard",
"quantity" : "1",
"image" : "1531563759445.JPG",
"__v" : 0,
"assets_planned_end_date" : ISODate("2018-07-14T10:30:13.000Z"),
"assets_planned_start_date" : ISODate("2018-07-14T10:30:13.000Z"),
"users_list" : [
ObjectId("5a226aa9c5941e2f845667c3")
],
"outdoor_tracking" : []
},
{
"_id" : ObjectId("5b49cef1b8695590d4ea7203"),
"brand_id" : ObjectId("59e090a8bdd6d7a454a89305"),
"medium" : "Billboard 2",
"quantity" : "5",
"image" : "1531562115.JPG",
"__v" : 0,
"assets_planned_end_date" : ISODate("2018-07-14T10:30:13.000Z"),
"assets_planned_start_date" : ISODate("2018-07-14T10:30:13.000Z"),
"users_list" : [
ObjectId("5a1d0c63ea1c673058e88d2c")
],
"outdoor_tracking" : []
},
],
"__v" : 1
}
答案 0 :(得分:-1)
字段区分大小写,您需要使用
{"assets._id": req.params.id }