From 67abcefd25cf133774328b554bec3b43649a67c9 Mon Sep 17 00:00:00 2001 From: tidwall Date: Sat, 4 Jul 2020 10:12:06 -0700 Subject: [PATCH] Fixed wrong order for fields with SCAN This commit fixes an issue that happens when running SCAN on a collection that has objects with fields, causing field values to be mismatched with their respective keys. This only occured with json output, and is a regression from #534. Fixes #569 --- internal/server/scanner.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/server/scanner.go b/internal/server/scanner.go index 46813750..0bb877ee 100644 --- a/internal/server/scanner.go +++ b/internal/server/scanner.go @@ -399,13 +399,14 @@ func (sw *scanWriter) writeObject(opts ScanWriterParams) bool { } } else if len(sw.farr) > 0 { + fvs := orderFields(sw.fmap, sw.farr, opts.fields) jsfields = `,"fields":[` - for i := range sw.farr { + for i, fv := range fvs { if i > 0 { jsfields += `,` } if len(opts.fields) > i { - jsfields += strconv.FormatFloat(opts.fields[i], 'f', -1, 64) + jsfields += strconv.FormatFloat(fv.value, 'f', -1, 64) } else { jsfields += "0" }