ElemMatchObjectMatchExpression.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "use strict";
  2. var ArrayMatchingMatchExpression = require('./ArrayMatchingMatchExpression.js');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var ElemMatchObjectMatchExpression = module.exports = function ElemMatchObjectMatchExpression(){
  5. base.call(this);
  6. }, klass = ElemMatchObjectMatchExpression, base = ArrayMatchingMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  7. // File: expression_array.h lines: 77-77
  8. proto._sub = undefined;
  9. /**
  10. *
  11. * Writes a debug string for this object
  12. * @method debugString
  13. * @param level
  14. *
  15. */
  16. proto.debugString = function debugString(level){
  17. // File: expression_array.cpp lines: 106-109
  18. var debug = this._debugAddSpace(level);
  19. debug = debug + this.path() + " $elemMatch\n";
  20. return debug + this._sub.debugString(level + 1);
  21. };
  22. /**
  23. *
  24. * Return the _sub property
  25. * @method getChild
  26. *
  27. */
  28. proto.getChild = function getChild(){
  29. // File: expression_array.h lines: 74-73
  30. return this._sub;
  31. };
  32. /**
  33. *
  34. * Initialize the necessary items
  35. * @method init
  36. * @param path
  37. * @param type
  38. *
  39. */
  40. proto.init = function init(path, sub){
  41. // File: expression_array.cpp lines: 85-87
  42. this._sub = sub;
  43. return this.initPath(path);
  44. };
  45. /**
  46. *
  47. * Check if one of the items in the input array matches _sub
  48. * @method matchesArray
  49. * @param anArray
  50. * @param details
  51. *
  52. */
  53. proto.matchesArray = function matchesArray(anArray, details){
  54. // File: expression_array.cpp lines: 90-103
  55. for (var i in anArray) {
  56. var inner = anArray[i];
  57. if (!(inner instanceof Object))
  58. continue;
  59. if (this._sub.matchesBSON(inner, null)) {
  60. if (details && details.needRecord()) {
  61. details.setElemMatchKey(i);
  62. }
  63. return true;
  64. }
  65. }
  66. return false;
  67. };
  68. /**
  69. *
  70. * Return 1 since we have a single "sub"
  71. * @method numChildren
  72. *
  73. */
  74. proto.numChildren = function numChildren(){
  75. // File: expression_array.h lines: 73-72
  76. return 1;
  77. };
  78. /**
  79. *
  80. * clone this instance to a new one
  81. * @method shallowClone
  82. *
  83. */
  84. proto.shallowClone = function shallowClone(){
  85. // File: expression_array.h lines: 65-68
  86. var element = new ElemMatchObjectMatchExpression();
  87. element.init(this.path(), this._sub.shallowClone());
  88. return element;
  89. };