Companies
[
{ _id: 1, name: "Apple" },
{ _id: 2, name: "Microsoft" },
{ _id: 3, name: "Facebook" },
{ _id: 4, name: "Tesla" }
]
Is there a way to show name
filed in query to new format?
Example )
Companies.find({}).newFormat(document => name: document.name[0] + '****')
Expected Result:
[
{ _id: 1, name: "A****" },
{ _id: 2, name: "M****" },
{ _id: 3, name: "F****" },
{ _id: 4, name: "T****" }
]
2
Answers
You can use aggregate like this
you can do a projection with
$concat
and$substr
withfind
as wellplayground
if you want to add a variable number of "*" say based on the length of each name you can use
$reduce
playground