[SERVER-14330] Applying Array.isArray to a field containing a hyphen Created: 21/Jun/14 Updated: 10/Dec/14 Resolved: 08/Jul/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 2.6.1 |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Brad Miller | Assignee: | Kamran K. |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
I have a program which inspects every field in a document to see if it an array. This works fine for: db.bios.find({$where: "Array.isArray(this.awards)"}) But not for db.messages.find({$where: "Array.isArray(this.X-cc)"}) If I single-quote the parameter value in isArray it breaks the working use case: db.bios.find({$where: "Array.isArray('this.awards')"}) and seems to fix the broken use case: What I'm looking for is a generic solution that can be used in both scenarios. Thanks, Brad |
| Comments |
| Comment by Kamran K. [ 18/Jul/14 ] |
|
Glad to hear it worked! |
| Comment by Brad Miller [ 17/Jul/14 ] |
|
Hi Kamran - Apologies for my delay in getting back to you. Your suggestion worked perfectly. Thank you so much for your help. Brad |
| Comment by Kamran K. [ 02/Jul/14 ] |
|
Hi Brad, Have you had a chance to try the bracket notation suggestion? |
| Comment by Kamran K. [ 21/Jun/14 ] |
|
Hi Brad, 'X-cc' is not a valid JavaScript identifier, so you can't use dot notation to access that property. Instead, you should use bracket notation to avoid identifier restrictions with property names: Array.isArray(this['X-cc']) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors has a nice overview of bracket notation and dot notation for further reference. Hope that helps! |