Skip to content

MongoDB 对指定字段执行 trim 方法 #169

@Dream4ever

Description

@Dream4ever

解决过程

Google 关键词:mongodb remove space in documents field value

第一个搜索结果 Removing white spaces (leading and trailing) from string value 就给出了当前在用的 MongoDB 4.2 可以用的方法:

db.collection.update(
  {},
  [{ $set: { category: { $trim: { input: "$category" } } } }],
  { multi: true }
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions