Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Error in JSON serializations into URL parameters #32

@moxiegirl

Description

@moxiegirl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions