Comments (2)
I think the confusion is related to how/when I first developed and used this package. I was using mongoskin to execute queries. I see mongoskin hasn't been updated since 2016 -- Like I'm one to talk
At the time, mongoskin exposed a find
method that accepted the criteria and options as-is. db.Kitten.find(criteria, options).toArray(cb)
, for example.
I doubt the current version of mongoskin still support the options as-is. I believe it exposed find
from a mongodb library. But it was years ago -- I think it was before MongoDB 3.0.
Depending on the library you are using you'll likely need to cherry pick values from the returned options rather than passing it as-is.
My quick take on using a more up-to-date libarary (Mongoose 6.0.0) with results from query-to-mongo:
const mongoose = require('mongoose')
await mongoose.connect('mongodb://localhost:27017/test')
const kittySchema = new mongoose.Schema({
name: String,
age: Number,
})
const Kitten = mongoose.model('Kitten', kittySchema)
const queryString = "name=john&age>21&fields=name,age&sort=name,-age&offset=10&limit=10"
var q = q2m(queryString)
var query = Kitten.find(q.criteria)
if (q.options) {
if (q.options.fields) query = query.projection(q.options.fields)
if (q.options.sort) query = query.sort(q.options.sort)
if (q.options.skip) query = query.skip(q.options.skip)
if (q.options.limit) query = query.limit(q.options.limit)
}
const list = await query.exec()
Caveat: I have not run this example -- you may experience some turbulence.
from query-to-mongo.
After doing some more research, I've found that the find()
option exposed by MongoDB NodeJS Driver does support the options as returned by query-to-mongo.
- The Find method: https://mongodb.github.io/node-mongodb-native/4.4/interfaces/FindOptions.html#skip
- The FindOptions structure: https://mongodb.github.io/node-mongodb-native/4.4/interfaces/FindOptions.html
- The skip option: https://mongodb.github.io/node-mongodb-native/4.4/interfaces/FindOptions.html#skip
But I did fix the problem you pointed out in the document: offset
in returned object should be skip
.
from query-to-mongo.
Related Issues (15)
- Support for $or function HOT 3
- Support comparison operators with a=b query format HOT 6
- Fields generated have field name = true of false but 1 or 0 required HOT 5
- query by default _id HOT 3
- Support existence check encoded into the value HOT 1
- Filtering "not contains" string HOT 2
- URL encoded multiple negations not working as expected HOT 1
- How can I get a field count? HOT 1
- Commas in regex HOT 2
- Sometimes 'Infinity' is returned in the converted result HOT 4
- $and, $or HOT 1
- search support HOT 1
- Dates not working in New Zealand HOT 2
- Update npm HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from query-to-mongo.