简体   繁体   English

为什么过滤结果得到空结果?

[英]why filter result getting empty result?

why I am getting empty result while apply date filter query.为什么我在应用日期过滤查询时得到空结果。 I am using mongoose as ORM.我正在使用 mongoose 作为 ORM。 through mongo compass.通过 mongo 指南针。 i am getting correct result.but through mongoose it doesn't works我得到了正确的结果。但是通过 mongoose 它不起作用

I am doing like this我正在这样做

console.log('-------------11-----------');
      var a  = await this.orderModel
        .where('assigned_user')
        .equals(getLawyerAssignedOrderInput.user);

      console.log("**************1********");
      console.log(a);
      console.log("**************2********");
      console.log("**************244444444********");
      console.log("**************5555********",new Date (getLawyerAssignedOrderInput.start_date.toString()));
      console.log("**************6666********",getLawyerAssignedOrderInput.end_date.toString());
      console.log("**************66666677777777********",getLawyerAssignedOrderInput.start_date);
      console.log("**************66666677777777********",getLawyerAssignedOrderInput.start_date);
      var b  = await this.orderModel
        .where('assigned_user')
        .equals(getLawyerAssignedOrderInput.user)
        .where({
          created_at: {
            $gt: new Date(getLawyerAssignedOrderInput.start_date.toString()),
            $lt:  new Date(getLawyerAssignedOrderInput.end_date.toString()),
          },
        })

      console.log("**************2********");
      console.log("**************b********");
      console.log(b);

a variable has correct value getting four or 4 collection object .变量具有正确的值,获得四个或 4 个集合 object but after date filter I am getting empty array why?但是在日期过滤器之后我得到空数组,为什么?

my console output我的控制台 output

**************1********
[
  {
    is_api_call_tried: false,
    updated_at: 2022-01-03T13:00:11.569Z,
    created_at: 2022-01-03T11:08:31.427Z,
    order_frozen: false,
    status: 2,
    _id: 61d2d92e46e16328d033080b,
    category_id: 'dGVybTozNQ==',
    country_code: 91,
    coupon_code: '',
    coupon_code_discount_type: '',
    coupon_discount: 0,
    currency: 'INR',
    discount: 33,
    products: [ [Object] ],
    subtotal: 50,
    tax: 9,
    total_amount: 59,
    user: 61889ea9a67c2bafe7ebae88,
    user_email: 'hrithikpvkr@icloud.com',
    user_phone: 8894425572,
    call_schedule: [],
    required_documents: [],
    deliverables: [],
    __v: 0,
    paytm_order_id: 'Order_43830PM',
    paytm_transaction_token: 'd00b3d0aad22469db4ebe8346918a99f1641208111337',
    razorpay_order_id: 'order_IfFONbvVGn3f6p',
    payment_method: 9,
    payment_status_gateway: true,
    payment_status_user: true,
    frozen_by: 'cron',
    invoice_generation_date: 1641208501020,
    invoice_id: 237,
    invoice_url: 'https://ezylegal-uploaded-documents.s3.ap-south-1.amazonaws.com/1qyrh81641208501543.pdf',
    assigned_date: 2022-01-03T13:00:11.569Z,
    assigned_user: 617a111e35bc91fa7dcd5316
  },
  {
    is_api_call_tried: false,
    updated_at: 2022-01-03T11:24:50.445Z,
    created_at: 2022-01-03T11:20:00.844Z,
    order_frozen: false,
    status: 2,
    _id: 61d2dbe046e16328d0330863,
    category_id: 'dGVybTozNQ==',
    country_code: 91,
    coupon_code: '',
    coupon_code_discount_type: '',
    coupon_discount: 0,
    currency: 'INR',
    discount: 33,
    products: [ [Object] ],
    subtotal: 50,
    tax: 9,
    total_amount: 59,
    user: 618898f0a67c2bafe7ebad97,
    user_email: 'solankiaman520@gmail.com',
    user_phone: 9958936497,
    call_schedule: [],
    required_documents: [],
    deliverables: [],
    __v: 0,
    paytm_order_id: 'Order_45000PM',
    paytm_transaction_token: '95aec11ff241482ebbb0a789463d94fb1641208800723',
    razorpay_order_id: 'order_IfFaW5iftxcxTI',
    payment_method: 9,
    payment_status_gateway: true,
    payment_status_user: true,
    assigned_date: 2022-01-03T11:24:50.445Z,
    assigned_user: 617a111e35bc91fa7dcd5316
  },
  {
    is_api_call_tried: false,
    updated_at: 2022-01-03T12:56:39.634Z,
    created_at: 2022-01-03T11:31:57.710Z,
    order_frozen: false,
    status: 2,
    _id: 61d2dead46e16328d033090c,
    category_id: 'dGVybTozNA==',
    country_code: 91,
    coupon_code: '',
    coupon_code_discount_type: '',
    coupon_discount: 0,
    currency: 'INR',
    discount: 63,
    products: [ [Object], [Object], [Object] ],
    subtotal: 89,
    tax: 18,
    total_amount: 107,
    user: 618898f0a67c2bafe7ebad97,
    user_email: 'solankiaman520@gmail.com',
    user_phone: 9958936497,
    call_schedule: [],
    required_documents: [],
    deliverables: [],
    __v: 0,
    paytm_order_id: 'Order_50157PM',
    paytm_transaction_token: '2a260e03d902463d9cf8bd89d995d1cf1641209517600',
    razorpay_order_id: 'order_IfFn8bpY8B944r',
    payment_method: 9,
    payment_status_gateway: true,
    payment_status_user: true,
    frozen_by: 'cron',
    invoice_generation_date: 1641210120032,
    invoice_id: 239,
    invoice_url: 'https://ezylegal-uploaded-documents.s3.ap-south-1.amazonaws.com/ryonpo1641210120043.pdf',
    assigned_date: 2022-01-03T12:56:39.634Z,
    assigned_user: 617a111e35bc91fa7dcd5316
  },
  {
    is_api_call_tried: false,
    updated_at: 2022-01-04T05:48:52.504Z,
    created_at: 2022-01-03T12:53:00.591Z,
    order_frozen: false,
    status: 2,
    _id: 61d2f1ab46e16328d0330a88,
    category_id: 'dGVybTozNQ==',
    country_code: 91,
    coupon_code: '',
    coupon_code_discount_type: '',
    coupon_discount: 0,
    currency: 'INR',
    discount: 14,
    products: [ [Object] ],
    subtotal: 20,
    tax: 4,
    total_amount: 24,
    user: 618898f0a67c2bafe7ebad97,
    user_email: 'solankiaman520@gmail.com',
    user_phone: 9958936497,
    call_schedule: [],
    required_documents: [],
    deliverables: [],
    __v: 0,
    paytm_order_id: 'Order_62259PM',
    paytm_transaction_token: 'f5f3f364c7854cf587f4db8029d91ecf1641214380360',
    razorpay_order_id: 'order_IfHAkLpMy7MHju',
    payment_method: 9,
    payment_status_gateway: true,
    payment_status_user: true,
    assigned_date: 2022-01-04T05:48:52.504Z,
    assigned_user: 617a111e35bc91fa7dcd5316
  }
]
**************2********
**************244444444********
**************5555******** 2019-12-31T18:30:00.000Z
**************6666******** Mon Jan 03 2022
**************66666677777777******** Wed Jan 01 2020
**************66666677777777******** Wed Jan 01 2020
Mongoose: orders.find({ assigned_user: ObjectId("617a111e35bc91fa7dcd5316"), created_at: { '$gt': new Date("Tue, 31 Dec 2019 18:30:00 GMT"), '$lt': new Date("Sun, 02 Jan 2022 18:30:00 GMT") }}, { projection: {} })
**************2********
**************b********
[]

my collection structure我的收藏结构

{"_id":{"$oid":"61d2d92e46e16328d033080b"},"is_api_call_tried":false,"updated_at":{"$date":"2022-01-03T13:00:11.569Z"},"created_at":{"$date":"2022-01-03T11:08:31.427Z"},"order_frozen":false,"status":2,"category_id":"dGVybTozNQ==","country_code":91,"coupon_code":"","coupon_code_discount_type":"","coupon_discount":0,"currency":"INR","discount":33,"products":[{"updated_at":{"$date":"2021-12-30T08:40:24.478Z"},"created_at":{"$date":"2021-12-30T08:40:24.478Z"},"status":0,"discount":40,"tax":9,"regular_price":83,"sale_price":50,"_id":{"$oid":"61d2d92e46e16328d033080c"},"amount":50,"assigned_user":{"$oid":"61889ea9a67c2bafe7ebae88"},"calltime_purchased":null,"product_id":"cHJvZHVjdF92YXJpYXRpb246NTA4","product_name":"Will - Document draft - Customize","deliverables":[]}],"subtotal":50,"tax":9,"total_amount":59,"user":{"$oid":"61889ea9a67c2bafe7ebae88"},"user_email":"hrithikpvkr@icloud.com","user_phone":8894425572,"call_schedule":[],"required_documents":[],"deliverables":[],"__v":0,"paytm_order_id":"Order_43830PM","paytm_transaction_token":"d00b3d0aad22469db4ebe8346918a99f1641208111337","razorpay_order_id":"order_IfFONbvVGn3f6p","payment_method":9,"payment_status_gateway":true,"payment_status_user":true,"frozen_by":"cron","invoice_generation_date":1641208501020,"invoice_id":237,"invoice_url":"https://ezylegal-uploaded-documents.s3.ap-south-1.amazonaws.com/1qyrh81641208501543.pdf","assigned_date":{"$date":"2022-01-03T13:00:11.569Z"},"assigned_user":{"$oid":"617a111e35bc91fa7dcd5316"}}

any suggestion?有什么建议吗?

It seems to me that the created_at's data type is causing an issue.在我看来,created_at 的数据类型引起了问题。

 created_at: {
            $gt: new Date(getLawyerAssignedOrderInput.start_date.toString()),
            $lt:  new Date(getLawyerAssignedOrderInput.end_date.toString()),

Can you please try ISO date string?你能试试ISO日期字符串吗?

Since自从

 console.log("**************5555********",new Date (getLawyerAssignedOrderInput.start_date.toString())); console.log("**************66666677777777********",getLawyerAssignedOrderInput.start_date);

Results with结果与

 **************5555******** 2019-12-31T18:30:00.000Z *************66666677777777******** Wed Jan 01 2020

it must be time zone issue.一定是时区问题。 Try to pass getLawyerAssignedOrderInput.start_date directly:尝试直接传递getLawyerAssignedOrderInput.start_date

 $gt: getLawyerAssignedOrderInput.start_date,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM