Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to encapsulate the query string into a single URL parameter #69

Open
mozrat opened this issue Aug 7, 2017 · 1 comment
Open

Want to encapsulate the query string into a single URL parameter #69

mozrat opened this issue Aug 7, 2017 · 1 comment

Comments

@mozrat
Copy link

mozrat commented Aug 7, 2017

Hello - great project.

My requirements are slightly different to the default behaviour of node-mongo-querystring.

Given a URL like /?mongoquery=name=simon^location=London&page=2&rows=10

I would like to access my Mongo database query just from the mongoquery URL parameter.

I considered using node-mongo-querystring and base64 encoding the query so that it could be encapsulated, but that kills URL readability. Is there a good solution you can think of?

@Starefossen
Copy link
Contributor

Starefossen commented Aug 7, 2017

Hi @mozrat and thanks for the kind words.

I think this should be possible to achieve but you need to select some other query separator (like $) in order for this to work. Lets consider the following example.

?mongoquery=name=simon$location=London&page=2&rows=10
const qs = require('querystring');

const params = querystring.parse(req.querystring, '&');
console.log(params); // { mongoquery: "name=simon$location=London", page: 2, rows: 10 }

const queries = querystring.parse(params.mongoquery, '$');
console.log(queries); // { name: "simon", location: "London" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants