数组无意中被转换为超级对象

数组波纹pipe(query.conditions)以某种方式转换为对象,任何想法为什么以及如何防止它?

请求:

supertest(options.url) .get('/api/action') .expect(200) .query({ conditions: [ { 'user' : user._id }, { 'type' : 14 }, { 'what' : 4 }, ] }) 

服务器得到什么:

 { "conditions": { "user": "5592cc851f3febd016dae920", "type": "14", "what": "4" } } 

superagent 查询string序列化似乎存在问题 (由supertest )。

要解决这个问题,你可以在你的数据上使用qs.stringify()

 var qs = require('qs'); ... supertest(options.url) .get('/api/action') .expect(200) .query(qs.stringify({ conditions: [ { 'user' : user._id }, { 'type' : 14 }, { 'what' : 4 }, ] })) 

(如果可能的话,可能更适合于POST JSON)