Unexpected result when attempting to query multiple items in DocumentDB
hi,
we have documents stored follows:
{ "id": "100045", "foo": { "name": "xyz", "description": "abc", "id": 100045, }, "_rid": "yxxxxxx==", "_ts": 1412706606, "_self": "xxx00", "_attachments": "attachments/" }
notice actual content stored under "foo" property.
we have following stored procedure accepts array of ids , returns matching documents:
function (ids) { var context = getcontext(); var collection = context.getcollection(); var response = context.getresponse(); var selflink = collection.getselflink(); if (!ids || ids.length === 0) { return response.setbody([]); } var = 0; var result = []; // begin execution runquery(i++); // executes query function runquery(index) { var id = ids[index]; var query = 'select t.foo t t.id ="' + id + '"'; collection.querydocuments(selflink, query, {}, callback); } // handles single result callback function callback(error, singleresult) { if (error) { throw error; } else { result.push(singleresult[0]); if (i < ids.length) { runquery(i++); // query next item } else { return response.setbody(result); } } } }
notice select statement specifies inner document `select t.foo`.
however, result contains unwanted `foo` property, follows:
[ { "foo": { "name": "xyz", "description": "abc", "id": 100045 }, { "foo": { "name": "aaa", "description": "bbb", "id": 100046, } ]
the expected result following:
[ { "name": "xyz", "description": "abc", "id": 10045 }, { "name": "aaa", "description": "bbb", "id": 100046, } ]
i can fix changing `result.push(singleresult[0].doc);`
but looks bug me.
thanks
can please change "select value t.foo t t.id = ...". value keyword returns json value in query results.
btw, please email me @ arramac @ microsoft dot com in case discuss scenario in more detail.
Microsoft Azure > Azure Cosmos DB
Comments
Post a Comment