我想使用findOne(或find)搜索MongoDB,不幸的是我正试图从记录中访问一个值,但我似乎无法,也许这是因为它是一个孩子?
我正在尝试使用order_number,返回意味着返回将为null ....使用域工作!
order_number可以在customer_details中找到!
我试图使用的数据库函数(现在很简单):
dbconnect.createConnection()
refund.findOne({domain: domain, order_number: order_number}, (err, docs) => {
console.log('database return in addRefund ' + docs)
dbconnect.closeConnection();
})
(即使存在也返回null)
物体:
{
"_id": {
"$oid": "5c83d0d5ce02f50019b1b146"
},
"refundDetails": {
"refund": {
"shipping": {
"amount": 10,
"tax": 0,
"maximum_refundable": 10
},
"refund_line_items": [
{
"quantity": 1,
"line_item_id": 1808377315391,
"location_id": null,
"restock_type": "no_restock",
"price": "15.44",
"subtotal": "15.44",
"total_tax": "0.00",
"discounted_price": "15.44",
"discounted_total_price": "15.44",
"total_cart_discount_amount": "0.00"
},
{
"quantity": 1,
"line_item_id": 1808377348159,
"location_id": null,
"restock_type": "no_restock",
"price": "28.32",
"subtotal": "28.32",
"total_tax": "0.00",
"discounted_price": "28.32",
"discounted_total_price": "28.32",
"total_cart_discount_amount": "0.00"
}
],
"transactions": []
},
"customer_details": [
{
"order": {
"customer_name": "ewfefwefw grant",
"customer_email": "[email protected]",
"order_id": 778365730879,
"order_number": 1023,
"order_date": "2019-02-16T05:58:57-05:00",
"total_price": "53.76",
"subtotal_price": "43.76",
"shipping_price": "10.00",
"total_tax": "0.00",
"items": [
{
"id": 1808377315391,
"variant_id": 7051095769151,
"title": "Womens Summer Black Camis Dress",
"name": "Womens Summer Black Camis Dress - Black / S",
"quantity": 1,
"price": "15.44",
"product_id": 561553309759
},
{
"id": 1808377348159,
"variant_id": 7051095310399,
"title": "2017 Summer Women Dress Sexy",
"name": "2017 Summer Women Dress Sexy - Black / L",
"quantity": 1,
"price": "28.32",
"product_id": 561553244223
}
],
"image_links": [
{
"product_id": 561553309759,
"image_src": ewfewfwefwefw,
"varrient_id": []
},
{
"product_id": 561553309759,
"image_src": ewfewfwefewf,
"varrient_id": [
7051095769151,
7051095834687,
7051095867455,
7051095900223
]
},
{
"product_id": 561553244223,
"image_src": "qwfefefwe,
"varrient_id": []
}
],
"fullfillmentText": "Hi, Please find your order details below:"
}
}
]
},
"domain": "dwdwd.wdwd.com",
"__v": 0
}
非常感谢帮助,谢谢!
如果我理解你正确,你试图以错误的方式访问财产。
试试这个:
refund.findOne({domain: domain, 'customer_details.order.order_number': order_number}, (err, docs) => {
console.log('database return in addRefund ' + docs)
})
希望它会有所帮助!