radiks-server
radiks-server copied to clipboard
Error in JSON serializations into URL parameters
From enginnering thread Public slack.
xanderjakeq
how do I make an or query with radiks like the one described here: https://docs.mongodb.com/manual/reference/operator/query/or/ (edited)
Is there a way I could do this @Hank?
Hank:
yes - you can basically enter any query you’d pass to the mongoDB find API. just use the equivalent JSON query syntax in fetchList or whatever you’re using
so
find.({ $or: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] })
The equivalent would be
`fetchList({ $or: [ {
Hank yeah i think that should work.
try it out and confirm?
xanderjakeq 21 hours ago okay thanks! I have this
fetchList({
$or: [
{
offset,
limit,
author: {
$ne: username
},
notif_for: subbed_models,
sort: '-createdAt'
},
{
offset,
limit,
author: {
$ne: username
},
mentions: username,
sort: '-createdAt'
}
]
});
but I'm getting this error
VM433:1 GET http://localhost:5000/radiks/models/find?$or[][offset]=0&$or[][limit]=20&$or[][author][$ne]=xanderjakeq2.id.blockstack&$or[][notif_for][]=2ba0fcc064b0-45ed-9cac-d8df5054852a&[sort]=-createdAt&$or[][offset]=0&$or[][limit]=20&$or[][author][$ne]=xanderjakeq2.id.blockstack&$or[][mentions]=xanderjakeq2.id.blockstack&$or[][sort]=-createdAt&radiksType=Notification 500 (Internal Server Error)
Hank: can you post the actual error from radiks-server?
xanderjakeq
MongoError: $or must be an array
at Connection.<anonymous> (C:\Dev\Websites\startups\anylist\server\node_modules\mongodb\lib\core\connection\pool.js:466:61)
at Connection.emit (events.js:189:13)
at processMessage (C:\Dev\Websites\startups\anylist\server\node_modules\mongodb\lib\core\connection\connection.js:364:10)
at TLSSocket.<anonymous> (C:\Dev\Websites\startups\anylist\server\node_modules\mongodb\lib\core\connection\connection.js:533:15)
at TLSSocket.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at TLSSocket.Readable.push (_stream_readable.js:220:10)
at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
Hank:
i see - this seems like a bug in how the JSON gets serialized into URL parameters also, you can’t put those pagination params inside of the $or. it needs to be ‘top level’ to the query. otherwise, mongoDB will be looking for models where offset = 0, for example
xanderjakeq
ahh okay is that bug easy to fix? if so, I could wait before I try doing some workarounds
Hank:
i’m not quite sure. a workaround could be to do 2 separate queries
I think this issue is caused from here: https://github.com/blockstack/radiks/blob/master/src/api.ts#L31
The client formats your JSON query, but is turning those HTTP params into a "hash" - at least as to what the server sees. We need to change either that client-side code or the server code to make sure the JSON you're passing be properly deserialized on the server.
fixed by #36 and #40