请教一个 mongoose 的问题

2021-09-08 22:50:57 +08:00
 indo

最近写了一个爬虫去采集数据,数据结构大概是

{
  id: 'LY-0002-06',
  developers: 'project_developers',
  name: 'project_name',
  pre_licenses: [ '201959', '201963', '202001' ],
  phone_num: '3189828',
  address: 'address',
  purpose: [ 'useful1', 'useful2', 'useful3' ],
  land_source: '出让',
  land_area: '38513.48',
  land_level: '',
  cover_area: '6559.98',
  building_area: '77025.49',
  PR: '1.999',
  GPR: '30%',
  building_density: '17.02%',
  project_cost: '223610000',
  commencement_data: '2019 年 04 月 08 日',
  completion_data: '2020 年 09 月 28 日',
  construction_unit: 'c_unit',
  survey_unit: 's_unit',
  approve_sale: {
    apartment: { number: '724', area: '71905.13' },
    shop: { number: '0', area: '0' },
    office: { number: '0', area: '0' },
    parking: { number: '618', area: '19488.54' },
    other: { number: '0', area: '0' }
  },
  selling: {
    apartment: { number: '13', area: '1038.96' },
    shop: { number: '0', area: '0' },
    office: { number: '0', area: '0' },
    parking: { number: '30', area: '951.6' },
    other: { number: '0', area: '0' }
  },
  sold: {
    apartment: { number: '711', area: '70866.17' },
    shop: { number: '0', area: '0' },
    office: { number: '0', area: '0' },
    parking: { number: '588', area: '18536.94' },
    other: { number: '0', area: '0' }
  },
  building: [
    { pid: 'LY-0002-06', name: '1', id: '195231' },
    { pid: 'LY-0002-06', name: '2', id: '195232' },
    { pid: 'LY-0002-06', name: '3', id: '195233' },
    { pid: 'LY-0002-06', name: '5', id: '195234' },
    { pid: 'LY-0002-06', name: '6', id: '195295' },
    { pid: 'LY-0002-06', name: '8', id: '195296' },
    { pid: 'LY-0002-06', name: '9', id: '195271' },
    { pid: 'LY-0002-06', name: '10', id: '195272' },
    { pid: 'LY-0002-06', name: '11', id: '195297' },
    { pid: 'LY-0002-06', name: '12', id: '195273' },
    { pid: 'LY-0002-06', name: '13', id: '195298' },
    { pid: 'LY-0002-06', name: '15', id: '195299' },
    { pid: 'LY-0002-06', name: '16', id: '195300' }
  ]
}

目前是使用 mongoose 的 findOneAndUpdate 方法去新增或更新数据,回调函数只能读取到修改前或修改后的整条记录的值。 目前的需求是我希望能够知道每次变更数据时,具体修改了哪个字段该怎么办呢?

716 次点击
所在节点    问与答
2 条回复
ch2
2021-09-08 23:05:37 +08:00
difflib 了解一下
indo
2021-09-08 23:18:39 +08:00
@ch2 感谢回复,我去搜一搜。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/800712

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX