Giter VIP home page Giter VIP logo

Comments (2)

pbatey avatar pbatey commented on July 20, 2024

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.

pbatey avatar pbatey commented on July 20, 2024

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.

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.