1 | /**
|
2 | * 注文検索サンプル
|
3 | */
|
4 | const moment = require('moment');
|
5 | const mongoose = require('mongoose');
|
6 | const domain = require('../');
|
7 |
|
8 | async function main() {
|
9 | await mongoose.connect(process.env.MONGOLAB_URI);
|
10 |
|
11 | const orderRepo = new domain.repository.Order(mongoose.connection);
|
12 |
|
13 | const count = await orderRepo.count({
|
14 | project: { id: { $eq: 'cinerino' } },
|
15 | orderDate: {
|
16 | $gte: moment().add(-6, 'months').toDate(),
|
17 | $lte: moment().toDate(),
|
18 | }
|
19 | });
|
20 | console.log(count);
|
21 | return;
|
22 |
|
23 | const orders = await orderRepo.search({
|
24 | project: { id: { $eq: 'oyatsu-production' } },
|
25 | // orderDateFrom: moment().add(-3, 'weeks').toDate(),
|
26 | // orderDateThrough: moment().toDate(),
|
27 | orderDate: {
|
28 | $gte: moment().add(-12, 'months').toDate(),
|
29 | $lte: moment().toDate(),
|
30 | },
|
31 | // paymentMethods: {
|
32 | // typeOfs: [domain.factory.paymentMethodType.MovieTicket],
|
33 | // paymentMethodIds: ['xxx']
|
34 | // },
|
35 | seller: { ids: ['5cef8cc57261bf0012ad2f3a'] },
|
36 | // customer: {
|
37 | // ids: ['xxx'],
|
38 | // identifiers: [{ name: '', value: '' }],
|
39 | // givenName: 'xxx'
|
40 | // },
|
41 | // acceptedOffers: {
|
42 | // itemOffered: {
|
43 | // ids: ['xxx'],
|
44 | // reservationFor: { ids: ['xxx'] }
|
45 | // }
|
46 | // },
|
47 | limit: 20,
|
48 | page: 20,
|
49 | sort: { orderDate: -1 }
|
50 | });
|
51 | // console.log(orders);
|
52 | console.log(orders.length, 'orders found.');
|
53 | // console.log(typeof orders[0].id);
|
54 | // console.log(typeof orders[0].acceptedOffers);
|
55 | // console.log(orders[0].orderDate instanceof Date);
|
56 |
|
57 | // const res = await orderRepo.orderModel.find({
|
58 | // $and: [
|
59 | // { orderDate: { $gte: moment().add(-3, 'days').toDate() } },
|
60 | // { orderDate: { $lte: moment().toDate() } },
|
61 | // { confirmationNumber: { $in: ['0', '517205'] } },
|
62 | // {
|
63 | // 'paymentMethods.typeOf': {
|
64 | // $exists: true,
|
65 | // $in: [domain.factory.paymentMethodType.CreditCard, domain.factory.paymentMethodType.MovieTicket]
|
66 | // }
|
67 | // },
|
68 | // {
|
69 | // 'customer.identifier': {
|
70 | // $exists: true,
|
71 | // $in: [
|
72 | // { name: 'clientId', value: 'xxx' }
|
73 | // ]
|
74 |
|
75 | // }
|
76 | // }
|
77 | // ]
|
78 | // })
|
79 | // .sort({ orderDate: 1 })
|
80 | // .explain();
|
81 | // console.log(res[0].executionStats.allPlansExecution.map((e) => e.executionStages));
|
82 |
|
83 | // await mongoose.disconnect();
|
84 | }
|
85 |
|
86 | main().then(() => {
|
87 | console.log('success!');
|
88 | }).catch((error) => {
|
89 | console.error(error);
|
90 | process.exit(1);
|
91 | });
|