首页 > V2EX > V2EX-请教一个 mongoose 的问题
2021
09-08

V2EX-请教一个 mongoose 的问题

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

from V2EX-最新主题 https://ift.tt/3zXrqw6

最后编辑:
作者:分享菌
这个作者貌似有点懒,什么都没有留下。

留下一个回复