Error when I save a particular format of data[mongo db]
-
I try to save this code data:
[{"uid":"1","name":["Andreas"]}]
where uid is a field and name is a array. But when I do db.setObject I obtain this error:
Modifiers operate on fields but we found a Array instead. For example: {$mod: {<field>: ...}} not
Anyone can help me to save in my format?
-
you need to wrap it like
{"value": [{"uid":1,"name":["Andreas"]}]}
.Arrays are no (direct) instances of Objects;Thus not allowed to be used withindb.setObject
.EDIT: Actually
[] instanceof Object === true
. It's just not allowed by the database clients since Arrays are no conventional key/value stores.
Copyright © 2024 NodeBB | Contributors