-
Notifications
You must be signed in to change notification settings - Fork 260
Open
Description
I'm experiencing strange behaviour when trying to query more complex JSON documents in embedded mode. When the document that is inserted inserted to tiedot is created from a string via json.Unmarshal() it can be queried successfully. In case it is created from a directly initialized object it can not be queried.
Example object is taken from the example in documentation:
{"Name": [
{"PenName": "Joshua"},
{"PenName": ["John", "David"]}
]}
Consider the following code snippet:
_, err = coll.Insert(jsonDoc)
query := map[string]interface{}{
"eq": "John",
"in": []interface{}{"Name", "PenName"},
}
queryResult := make(map[int]struct{})
if err := db.EvalQuery(query, coll, &queryResult); err != nil {
panic(err)
}
Query returns any data only in a case when jsonDoc is created as:
s := `{"Name": [{"PenName": "Joshua"}, {"PenName": ["John", "David"]}]}`
var jsonDoc map[string]interface{}
json.Unmarshal([]byte(s), &jsonDoc)
but does not work when created as:
jsonDoc := map[string]interface{}{
"Name": []interface{}{
map[string]interface{}{
"PenName": "Joshua",
},
map[string]interface{}{
"PenName": []string{"John", "David"},
},
},
}
From my understanding these two methods of creating jsonDoc are equivalent. What I'm missing?
Metadata
Metadata
Assignees
Labels
No labels