diff --git a/README.md b/README.md index 757233a..83d6cc1 100644 --- a/README.md +++ b/README.md @@ -104,10 +104,10 @@ parser.parse('filter={"$or":[{"key1":"value1"},{"key2":"value2"}]}&name=Telstra' #### Populate operators - Useful to populate sub-document(s) in query. Works with `MongooseJS`. Please see [Mongoose Populate](http://mongoosejs.com/docs/populate.html) for more details -- Supports deep populate with delimiter ":" +- Supports deep populate with delimiter ":" to indicate deep populate - Below example & `test-populate.spec.ts` for more details - See [Mongoose Docs](https://mongoosejs.com/docs/populate.html#deep-populate) -- Allows to populate with only selected fields +- Allows to populate with only selected fields with "." to indicate field selection - Default operator key is `populate` ```js @@ -117,7 +117,8 @@ parser.parse('populate=createdBy:friends.name,createdBy.name,likedBy.name'); // path: 'createdBy', // select: 'name', // populate: { -// path: 'name', +// path: 'friends', +// select: 'name', // } // }, { // path: 'likedBy', diff --git a/package-lock.json b/package-lock.json index d37c007..47008d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mongoose-query-parser", - "version": "1.2.1", + "version": "1.3.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mongoose-query-parser", - "version": "1.2.1", + "version": "1.3.1", "license": "MIT", "dependencies": { "lodash": "^4.17.21", diff --git a/package.json b/package.json index 17707a3..49be49d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-query-parser", - "version": "1.3.0", + "version": "1.3.1", "description": "Convert url query string to MongooseJs friendly query object including advanced filtering, sorting, population, string template, type casting and many more...", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/src/test.spec.ts b/src/test.spec.ts index b94415d..9da731e 100644 --- a/src/test.spec.ts +++ b/src/test.spec.ts @@ -113,7 +113,7 @@ class Tester { @test('should parse deep populate') deepPopulateParse() { const parser = new MongooseQueryParser(); - const qry = '_id=1&populate=p1,p2:p3.p4,p2:p3.p5,p6:p7'; + const qry = '_id=1&populate=p1,p2:p3.p4,p2:p3:p5,p6:p7'; const parsed = parser.parse(qry); assert.isNotEmpty(parsed.populate); assert.isTrue(parsed.populate.length === 3); @@ -121,7 +121,7 @@ class Tester { if (p.path === 'p2') { assert.isTrue(p.populate.path === 'p3'); assert.isTrue(p.populate.select.includes('p4')); - assert.isTrue(p.populate.select.includes('p5')); + assert.isTrue(p.populate.populate.path === 'p5'); } if (p.path === 'p6') { assert.isTrue(p.populate.path === 'p7');