V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
indo
V2EX  ›  问与答

请教一个 mongoose 的问题

  •  1
     
  •   indo · 2021-09-08 22:50:57 +08:00 · 705 次点击
    这是一个创建于 953 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    2 条回复    2021-09-08 23:18:39 +08:00
    ch2
        1
    ch2  
       2021-09-08 23:05:37 +08:00
    difflib 了解一下
    indo
        2
    indo  
    OP
       2021-09-08 23:18:39 +08:00 via iPhone
    @ch2 感谢回复,我去搜一搜。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5551 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 02:56 · PVG 10:56 · LAX 19:56 · JFK 22:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.