1.0.8 • Published 7 months ago
mongoose-smart-query v1.0.8
mongoose-smart-query
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
Key | Description | Default |
---|---|---|
protectedFields | Fields that should not be included in the query results | '' |
defaultFields | Fields included in the default query results | '_id' |
defaultSort | Default sorting | '-id' |
defaultLimit | Number of documents per query | 20 |
fieldsForDefaultQuery | What fields to look for when making a query | '' |
pageQueryName | Key for pagination | '$page' |
limitQueryName | Key to limit | '$limit' |
fieldsQueryName | Key to get specific fields | '$fields' |
sortQueryName | Key for sorting | $sort |
queryName | Key for search | '$q' |
unwindName | mongodb 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.8
7 months ago
1.0.7
8 months ago
1.0.6
12 months ago
1.0.5
12 months ago
1.0.4
1 year ago
0.1.6
2 years ago
0.1.5
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.0
3 years ago
0.1.1
3 years ago
0.0.15
4 years ago
0.0.14
4 years ago
0.0.11
4 years ago
0.0.12
4 years ago
0.0.13
4 years ago
0.0.10
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.5
4 years ago
0.0.3
4 years ago
0.0.4
4 years ago
0.0.2
5 years ago
0.0.1
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
1 year ago