1.0.4 • Published 27 days ago

mongoose-smart-query v1.0.4

Weekly downloads
10
License
MIT
Repository
github
Last release
27 days ago

mongoose-smart-query

npm version Testing

mongoose-smart-query toma como entrada un objeto (ejemplo: req.query) e interpreta las condiciones para poder realizar una consulta 'inteligente', de acuerdo al esquema definido en mongoose. Las consultas se las realiza totalmente con aggregate.

Options

  • All fields below are optional.
  • All the fields are of type string, except the defaultLimit field which is of type number
KeyDescriptionDefault
protectedFieldsFields that should not be included in the query results''
defaultFieldsFields included in the default query results'_id'
defaultSortDefault sorting'-id'
defaultLimitNumber of documents per query20
fieldsForDefaultQueryWhat fields to look for when making a query''
pageQueryNameKey for pagination'$page'
limitQueryNameKey to limit'$limit'
fieldsQueryNameKey to get specific fields'$fields'
sortQueryNameKey for sorting$sort
queryNameKey for search'$q'
unwindNamemongodb unwind documents'$unwind'

Methods

Example

This is a simple mongoose model for persons:

const PersonSchema = new mongoose.Schema({
  name: String,
  random: Number,
  birthday: Date,
  colours: [String],
  password: String,
  bestFriend: { type: mongoose.Types.ObjectId, ref: 'persons' },
})
PersonSchema.plugin(mongooseSmartQuery, {
  defaultFields: 'name',
  protectedFields: 'password',
  fieldsForDefaultQuery: 'name bestFriend.name',
})
const Persons = mongoose.model('persons', PersonSchema)
1.0.4

27 days ago

0.1.6

7 months ago

0.1.5

12 months ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

4 years ago

0.0.1

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

1 month ago