MatchExpressionParser.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. "use strict"
  2. // Autogenerated by cport.py on 2013-09-17 14:37
  3. var MatchExpressionParser = module.exports = function (){
  4. }, klass = MatchExpressionParser, base = Object , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  5. /**
  6. *
  7. * This documentation was automatically generated. Please update when you touch this function.
  8. * @method _isExpressionDocument
  9. * @param
  10. *
  11. */
  12. proto._isExpressionDocument = function _isExpressionDocument( /* const BSONElement& e */ ){
  13. // File: expression_parser.cpp lines: 340-355
  14. // bool MatchExpressionParser::_isExpressionDocument( const BSONElement& e ) {
  15. // if ( e.type() != Object )
  16. // return false;
  17. //
  18. // BSONObj o = e.Obj();
  19. // if ( o.isEmpty() )
  20. // return false;
  21. //
  22. // const char* name = o.firstElement().fieldName();
  23. // if ( name[0] != '$' )
  24. // return false;
  25. //
  26. // if ( mongoutils::str::equals( "$ref", name ) )
  27. // return false;
  28. //
  29. // return true;
  30. // }
  31. }
  32. /**
  33. *
  34. * This documentation was automatically generated. Please update when you touch this function.
  35. * @method _parse
  36. * @param
  37. *
  38. */
  39. proto._parse = function _parse( /* const BSONObj& obj, bool topLevel */ ){
  40. // File: expression_parser.cpp lines: 217-319
  41. // StatusWithMatchExpression MatchExpressionParser::_parse( const BSONObj& obj, bool topLevel ) {
  42. //
  43. // std::auto_ptr<AndMatchExpression> root( new AndMatchExpression() );
  44. //
  45. // BSONObjIterator i( obj );
  46. // while ( i.more() ){
  47. //
  48. // BSONElement e = i.next();
  49. // if ( e.fieldName()[0] == '$' ) {
  50. // const char * rest = e.fieldName() + 1;
  51. //
  52. // // TODO: optimize if block?
  53. // if ( mongoutils::str::equals( "or", rest ) ) {
  54. // if ( e.type() != Array )
  55. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  56. // "$or needs an array" );
  57. // std::auto_ptr<OrMatchExpression> temp( new OrMatchExpression() );
  58. // Status s = _parseTreeList( e.Obj(), temp.get() );
  59. // if ( !s.isOK() )
  60. // return StatusWithMatchExpression( s );
  61. // root->add( temp.release() );
  62. // }
  63. // else if ( mongoutils::str::equals( "and", rest ) ) {
  64. // if ( e.type() != Array )
  65. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  66. // "and needs an array" );
  67. // std::auto_ptr<AndMatchExpression> temp( new AndMatchExpression() );
  68. // Status s = _parseTreeList( e.Obj(), temp.get() );
  69. // if ( !s.isOK() )
  70. // return StatusWithMatchExpression( s );
  71. // root->add( temp.release() );
  72. // }
  73. // else if ( mongoutils::str::equals( "nor", rest ) ) {
  74. // if ( e.type() != Array )
  75. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  76. // "and needs an array" );
  77. // std::auto_ptr<NorMatchExpression> temp( new NorMatchExpression() );
  78. // Status s = _parseTreeList( e.Obj(), temp.get() );
  79. // if ( !s.isOK() )
  80. // return StatusWithMatchExpression( s );
  81. // root->add( temp.release() );
  82. // }
  83. // else if ( mongoutils::str::equals( "atomic", rest ) ||
  84. // mongoutils::str::equals( "isolated", rest ) ) {
  85. // if ( !topLevel )
  86. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  87. // "$atomic/$isolated has to be at the top level" );
  88. // if ( e.trueValue() )
  89. // root->add( new AtomicMatchExpression() );
  90. // }
  91. // else if ( mongoutils::str::equals( "where", rest ) ) {
  92. // /*
  93. // if ( !topLevel )
  94. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  95. // "$where has to be at the top level" );
  96. // */
  97. // StatusWithMatchExpression s = expressionParserWhereCallback( e );
  98. // if ( !s.isOK() )
  99. // return s;
  100. // root->add( s.getValue() );
  101. // }
  102. // else if ( mongoutils::str::equals( "comment", rest ) ) {
  103. // }
  104. // else {
  105. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  106. // mongoutils::str::stream()
  107. // << "unknown top level operator: "
  108. // << e.fieldName() );
  109. // }
  110. //
  111. // continue;
  112. // }
  113. //
  114. // if ( _isExpressionDocument( e ) ) {
  115. // Status s = _parseSub( e.fieldName(), e.Obj(), root.get() );
  116. // if ( !s.isOK() )
  117. // return StatusWithMatchExpression( s );
  118. // continue;
  119. // }
  120. //
  121. // if ( e.type() == RegEx ) {
  122. // StatusWithMatchExpression result = _parseRegexElement( e.fieldName(), e );
  123. // if ( !result.isOK() )
  124. // return result;
  125. // root->add( result.getValue() );
  126. // continue;
  127. // }
  128. //
  129. // std::auto_ptr<ComparisonMatchExpression> eq( new EqualityMatchExpression() );
  130. // Status s = eq->init( e.fieldName(), e );
  131. // if ( !s.isOK() )
  132. // return StatusWithMatchExpression( s );
  133. //
  134. // root->add( eq.release() );
  135. // }
  136. //
  137. // if ( root->numChildren() == 1 ) {
  138. // const MatchExpression* real = root->getChild(0);
  139. // root->clearAndRelease();
  140. // return StatusWithMatchExpression( const_cast<MatchExpression*>(real) );
  141. // }
  142. //
  143. // return StatusWithMatchExpression( root.release() );
  144. // }
  145. }
  146. /**
  147. *
  148. * This documentation was automatically generated. Please update when you touch this function.
  149. * @method _parseAll
  150. * @param
  151. *
  152. */
  153. proto._parseAll = function _parseAll( /* const char* name,$/;" */ ){
  154. // File: expression_parser.cpp lines: 512-583
  155. // StatusWithMatchExpression MatchExpressionParser::_parseAll( const char* name,
  156. // const BSONElement& e ) {
  157. // if ( e.type() != Array )
  158. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$all needs an array" );
  159. //
  160. // BSONObj arr = e.Obj();
  161. // if ( arr.firstElement().type() == Object &&
  162. // mongoutils::str::equals( "$elemMatch",
  163. // arr.firstElement().Obj().firstElement().fieldName() ) ) {
  164. // // $all : [ { $elemMatch : {} } ... ]
  165. //
  166. // std::auto_ptr<AllElemMatchOp> temp( new AllElemMatchOp() );
  167. // Status s = temp->init( name );
  168. // if ( !s.isOK() )
  169. // return StatusWithMatchExpression( s );
  170. //
  171. // BSONObjIterator i( arr );
  172. // while ( i.more() ) {
  173. // BSONElement hopefullyElemMatchElement = i.next();
  174. //
  175. // if ( hopefullyElemMatchElement.type() != Object ) {
  176. // // $all : [ { $elemMatch : ... }, 5 ]
  177. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  178. // "$all/$elemMatch has to be consistent" );
  179. // }
  180. //
  181. // BSONObj hopefullyElemMatchObj = hopefullyElemMatchElement.Obj();
  182. // if ( !mongoutils::str::equals( "$elemMatch",
  183. // hopefullyElemMatchObj.firstElement().fieldName() ) ) {
  184. // // $all : [ { $elemMatch : ... }, { x : 5 } ]
  185. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  186. // "$all/$elemMatch has to be consistent" );
  187. // }
  188. //
  189. // StatusWithMatchExpression inner = _parseElemMatch( "", hopefullyElemMatchObj.firstElement() );
  190. // if ( !inner.isOK() )
  191. // return inner;
  192. // temp->add( static_cast<ArrayMatchingMatchExpression*>( inner.getValue() ) );
  193. // }
  194. //
  195. // return StatusWithMatchExpression( temp.release() );
  196. // }
  197. //
  198. // std::auto_ptr<AndMatchExpression> myAnd( new AndMatchExpression() );
  199. // BSONObjIterator i( arr );
  200. // while ( i.more() ) {
  201. // BSONElement e = i.next();
  202. //
  203. // if ( e.type() == RegEx ) {
  204. // std::auto_ptr<RegexMatchExpression> r( new RegexMatchExpression() );
  205. // Status s = r->init( name, e );
  206. // if ( !s.isOK() )
  207. // return StatusWithMatchExpression( s );
  208. // myAnd->add( r.release() );
  209. // }
  210. // else if ( e.type() == Object && e.Obj().firstElement().getGtLtOp(-1) != -1 ) {
  211. // return StatusWithMatchExpression( ErrorCodes::BadValue, "no $ expressions in $all" );
  212. // }
  213. // else {
  214. // std::auto_ptr<EqualityMatchExpression> x( new EqualityMatchExpression() );
  215. // Status s = x->init( name, e );
  216. // if ( !s.isOK() )
  217. // return StatusWithMatchExpression( s );
  218. // myAnd->add( x.release() );
  219. // }
  220. // }
  221. //
  222. // if ( myAnd->numChildren() == 0 ) {
  223. // return StatusWithMatchExpression( new FalseMatchExpression() );
  224. // }
  225. //
  226. // return StatusWithMatchExpression( myAnd.release() );
  227. // }
  228. }
  229. /**
  230. *
  231. * This documentation was automatically generated. Please update when you touch this function.
  232. * @method _parseArrayFilterEntries
  233. * @param
  234. *
  235. */
  236. proto._parseArrayFilterEntries = function _parseArrayFilterEntries( /* ArrayFilterEntries* entries,$/;" */ ){
  237. // File: expression_parser.cpp lines: 445-468
  238. // Status MatchExpressionParser::_parseArrayFilterEntries( ArrayFilterEntries* entries,
  239. // const BSONObj& theArray ) {
  240. //
  241. // BSONObjIterator i( theArray );
  242. // while ( i.more() ) {
  243. // BSONElement e = i.next();
  244. //
  245. // if ( e.type() == RegEx ) {
  246. // std::auto_ptr<RegexMatchExpression> r( new RegexMatchExpression() );
  247. // Status s = r->init( "", e );
  248. // if ( !s.isOK() )
  249. // return s;
  250. // s = entries->addRegex( r.release() );
  251. // if ( !s.isOK() )
  252. // return s;
  253. // }
  254. // else {
  255. // Status s = entries->addEquality( e );
  256. // if ( !s.isOK() )
  257. // return s;
  258. // }
  259. // }
  260. // return Status::OK();
  261. //
  262. // }
  263. }
  264. /**
  265. *
  266. * This documentation was automatically generated. Please update when you touch this function.
  267. * @method _parseComparison
  268. * @param
  269. *
  270. */
  271. proto._parseComparison = function _parseComparison( /* const char* name,$/;" */ ){
  272. // File: expression_parser.cpp lines: 34-43
  273. // StatusWithMatchExpression MatchExpressionParser::_parseComparison( const char* name,
  274. // ComparisonMatchExpression* cmp,
  275. // const BSONElement& e ) {
  276. // std::auto_ptr<ComparisonMatchExpression> temp( cmp );
  277. //
  278. // Status s = temp->init( name, e );
  279. // if ( !s.isOK() )
  280. // return StatusWithMatchExpression(s);
  281. //
  282. // return StatusWithMatchExpression( temp.release() );
  283. // }
  284. }
  285. /**
  286. *
  287. * This documentation was automatically generated. Please update when you touch this function.
  288. * @method _parseElemMatch
  289. * @param
  290. *
  291. */
  292. proto._parseElemMatch = function _parseElemMatch( /* const char* name,$/;" */ ){
  293. // File: expression_parser.cpp lines: 471-509
  294. // StatusWithMatchExpression MatchExpressionParser::_parseElemMatch( const char* name,
  295. // const BSONElement& e ) {
  296. // if ( e.type() != Object )
  297. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$elemMatch needs an Object" );
  298. //
  299. // BSONObj obj = e.Obj();
  300. // if ( _isExpressionDocument( e ) ) {
  301. // // value case
  302. //
  303. // AndMatchExpression theAnd;
  304. // Status s = _parseSub( "", obj, &theAnd );
  305. // if ( !s.isOK() )
  306. // return StatusWithMatchExpression( s );
  307. //
  308. // std::auto_ptr<ElemMatchValueMatchExpression> temp( new ElemMatchValueMatchExpression() );
  309. // s = temp->init( name );
  310. // if ( !s.isOK() )
  311. // return StatusWithMatchExpression( s );
  312. //
  313. // for ( size_t i = 0; i < theAnd.numChildren(); i++ ) {
  314. // temp->add( theAnd.getChild( i ) );
  315. // }
  316. // theAnd.clearAndRelease();
  317. //
  318. // return StatusWithMatchExpression( temp.release() );
  319. // }
  320. //
  321. // // object case
  322. //
  323. // StatusWithMatchExpression sub = _parse( obj, false );
  324. // if ( !sub.isOK() )
  325. // return sub;
  326. //
  327. // std::auto_ptr<ElemMatchObjectMatchExpression> temp( new ElemMatchObjectMatchExpression() );
  328. // Status status = temp->init( name, sub.getValue() );
  329. // if ( !status.isOK() )
  330. // return StatusWithMatchExpression( status );
  331. //
  332. // return StatusWithMatchExpression( temp.release() );
  333. // }
  334. }
  335. /**
  336. *
  337. * This documentation was automatically generated. Please update when you touch this function.
  338. * @method _parseMOD
  339. * @param
  340. *
  341. */
  342. proto._parseMOD = function _parseMOD( /* const char* name,$/;" */ ){
  343. // File: expression_parser.cpp lines: 360-387
  344. // StatusWithMatchExpression MatchExpressionParser::_parseMOD( const char* name,
  345. // const BSONElement& e ) {
  346. //
  347. // if ( e.type() != Array )
  348. // return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, needs to be an array" );
  349. //
  350. // BSONObjIterator i( e.Obj() );
  351. //
  352. // if ( !i.more() )
  353. // return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, not enough elements" );
  354. // BSONElement d = i.next();
  355. // if ( !d.isNumber() )
  356. // return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, divisor not a number" );
  357. //
  358. // if ( !i.more() )
  359. // return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, not enough elements" );
  360. // BSONElement r = i.next();
  361. // if ( !d.isNumber() )
  362. // return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, remainder not a number" );
  363. //
  364. // if ( i.more() )
  365. // return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, too many elements" );
  366. //
  367. // std::auto_ptr<ModMatchExpression> temp( new ModMatchExpression() );
  368. // Status s = temp->init( name, d.numberInt(), r.numberInt() );
  369. // if ( !s.isOK() )
  370. // return StatusWithMatchExpression( s );
  371. // return StatusWithMatchExpression( temp.release() );
  372. // }
  373. }
  374. /**
  375. *
  376. * This documentation was automatically generated. Please update when you touch this function.
  377. * @method _parseNot
  378. * @param
  379. *
  380. */
  381. proto._parseNot = function _parseNot( /* const char* name,$/;" */ ){
  382. // File: expression_parser_tree.cpp lines: 55-91
  383. // StatusWithMatchExpression MatchExpressionParser::_parseNot( const char* name,
  384. // const BSONElement& e ) {
  385. // if ( e.type() == RegEx ) {
  386. // StatusWithMatchExpression s = _parseRegexElement( name, e );
  387. // if ( !s.isOK() )
  388. // return s;
  389. // std::auto_ptr<NotMatchExpression> n( new NotMatchExpression() );
  390. // Status s2 = n->init( s.getValue() );
  391. // if ( !s2.isOK() )
  392. // return StatusWithMatchExpression( s2 );
  393. // return StatusWithMatchExpression( n.release() );
  394. // }
  395. //
  396. // if ( e.type() != Object )
  397. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$not needs a regex or a document" );
  398. //
  399. // BSONObj notObject = e.Obj();
  400. // if ( notObject.isEmpty() )
  401. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$not cannot be empty" );
  402. //
  403. // std::auto_ptr<AndMatchExpression> theAnd( new AndMatchExpression() );
  404. // Status s = _parseSub( name, notObject, theAnd.get() );
  405. // if ( !s.isOK() )
  406. // return StatusWithMatchExpression( s );
  407. //
  408. // // TODO: this seems arbitrary?
  409. // // tested in jstests/not2.js
  410. // for ( unsigned i = 0; i < theAnd->numChildren(); i++ )
  411. // if ( theAnd->getChild(i)->matchType() == MatchExpression::REGEX )
  412. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$not cannot have a regex" );
  413. //
  414. // std::auto_ptr<NotMatchExpression> theNot( new NotMatchExpression() );
  415. // s = theNot->init( theAnd.release() );
  416. // if ( !s.isOK() )
  417. // return StatusWithMatchExpression( s );
  418. //
  419. // return StatusWithMatchExpression( theNot.release() );
  420. // }
  421. }
  422. /**
  423. *
  424. * This documentation was automatically generated. Please update when you touch this function.
  425. * @method _parseRegexDocument
  426. * @param
  427. *
  428. */
  429. proto._parseRegexDocument = function _parseRegexDocument( /* const char* name,$/;" */ ){
  430. // File: expression_parser.cpp lines: 402-442
  431. // StatusWithMatchExpression MatchExpressionParser::_parseRegexDocument( const char* name,
  432. // const BSONObj& doc ) {
  433. // string regex;
  434. // string regexOptions;
  435. //
  436. // BSONObjIterator i( doc );
  437. // while ( i.more() ) {
  438. // BSONElement e = i.next();
  439. // switch ( e.getGtLtOp() ) {
  440. // case BSONObj::opREGEX:
  441. // if ( e.type() == String ) {
  442. // regex = e.String();
  443. // }
  444. // else if ( e.type() == RegEx ) {
  445. // regex = e.regex();
  446. // regexOptions = e.regexFlags();
  447. // }
  448. // else {
  449. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  450. // "$regex has to be a string" );
  451. // }
  452. //
  453. // break;
  454. // case BSONObj::opOPTIONS:
  455. // if ( e.type() != String )
  456. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  457. // "$options has to be a string" );
  458. // regexOptions = e.String();
  459. // break;
  460. // default:
  461. // break;
  462. // }
  463. //
  464. // }
  465. //
  466. // std::auto_ptr<RegexMatchExpression> temp( new RegexMatchExpression() );
  467. // Status s = temp->init( name, regex, regexOptions );
  468. // if ( !s.isOK() )
  469. // return StatusWithMatchExpression( s );
  470. // return StatusWithMatchExpression( temp.release() );
  471. //
  472. // }
  473. }
  474. /**
  475. *
  476. * This documentation was automatically generated. Please update when you touch this function.
  477. * @method _parseRegexElement
  478. * @param
  479. *
  480. */
  481. proto._parseRegexElement = function _parseRegexElement( /* const char* name,$/;" */ ){
  482. // File: expression_parser.cpp lines: 390-399
  483. // StatusWithMatchExpression MatchExpressionParser::_parseRegexElement( const char* name,
  484. // const BSONElement& e ) {
  485. // if ( e.type() != RegEx )
  486. // return StatusWithMatchExpression( ErrorCodes::BadValue, "not a regex" );
  487. //
  488. // std::auto_ptr<RegexMatchExpression> temp( new RegexMatchExpression() );
  489. // Status s = temp->init( name, e.regex(), e.regexFlags() );
  490. // if ( !s.isOK() )
  491. // return StatusWithMatchExpression( s );
  492. // return StatusWithMatchExpression( temp.release() );
  493. // }
  494. }
  495. /**
  496. *
  497. * This documentation was automatically generated. Please update when you touch this function.
  498. * @method _parseSub
  499. * @param
  500. *
  501. */
  502. proto._parseSub = function _parseSub( /* const char* name,$/;" */ ){
  503. // File: expression_parser.cpp lines: 322-337
  504. // Status MatchExpressionParser::_parseSub( const char* name,
  505. // const BSONObj& sub,
  506. // AndMatchExpression* root ) {
  507. // BSONObjIterator j( sub );
  508. // while ( j.more() ) {
  509. // BSONElement deep = j.next();
  510. //
  511. // StatusWithMatchExpression s = _parseSubField( sub, root, name, deep );
  512. // if ( !s.isOK() )
  513. // return s.getStatus();
  514. //
  515. // if ( s.getValue() )
  516. // root->add( s.getValue() );
  517. // }
  518. //
  519. // return Status::OK();
  520. // }
  521. }
  522. /**
  523. *
  524. * This documentation was automatically generated. Please update when you touch this function.
  525. * @method _parseSubField
  526. * @param
  527. *
  528. */
  529. proto._parseSubField = function _parseSubField( /* const BSONObj& context,$/;" */ ){
  530. // File: expression_parser.cpp lines: 46-214
  531. // StatusWithMatchExpression MatchExpressionParser::_parseSubField( const BSONObj& context,
  532. // const AndMatchExpression* andSoFar,
  533. // const char* name,
  534. // const BSONElement& e ) {
  535. //
  536. // // TODO: these should move to getGtLtOp, or its replacement
  537. //
  538. // if ( mongoutils::str::equals( "$eq", e.fieldName() ) )
  539. // return _parseComparison( name, new EqualityMatchExpression(), e );
  540. //
  541. // if ( mongoutils::str::equals( "$not", e.fieldName() ) ) {
  542. // return _parseNot( name, e );
  543. // }
  544. //
  545. // int x = e.getGtLtOp(-1);
  546. // switch ( x ) {
  547. // case -1:
  548. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  549. // mongoutils::str::stream() << "unknown operator: "
  550. // << e.fieldName() );
  551. // case BSONObj::LT:
  552. // return _parseComparison( name, new LTMatchExpression(), e );
  553. // case BSONObj::LTE:
  554. // return _parseComparison( name, new LTEMatchExpression(), e );
  555. // case BSONObj::GT:
  556. // return _parseComparison( name, new GTMatchExpression(), e );
  557. // case BSONObj::GTE:
  558. // return _parseComparison( name, new GTEMatchExpression(), e );
  559. // case BSONObj::NE: {
  560. // StatusWithMatchExpression s = _parseComparison( name, new EqualityMatchExpression(), e );
  561. // if ( !s.isOK() )
  562. // return s;
  563. // std::auto_ptr<NotMatchExpression> n( new NotMatchExpression() );
  564. // Status s2 = n->init( s.getValue() );
  565. // if ( !s2.isOK() )
  566. // return StatusWithMatchExpression( s2 );
  567. // return StatusWithMatchExpression( n.release() );
  568. // }
  569. // case BSONObj::Equality:
  570. // return _parseComparison( name, new EqualityMatchExpression(), e );
  571. //
  572. // case BSONObj::opIN: {
  573. // if ( e.type() != Array )
  574. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$in needs an array" );
  575. // std::auto_ptr<InMatchExpression> temp( new InMatchExpression() );
  576. // Status s = temp->init( name );
  577. // if ( !s.isOK() )
  578. // return StatusWithMatchExpression( s );
  579. // s = _parseArrayFilterEntries( temp->getArrayFilterEntries(), e.Obj() );
  580. // if ( !s.isOK() )
  581. // return StatusWithMatchExpression( s );
  582. // return StatusWithMatchExpression( temp.release() );
  583. // }
  584. //
  585. // case BSONObj::NIN: {
  586. // if ( e.type() != Array )
  587. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$nin needs an array" );
  588. // std::auto_ptr<InMatchExpression> temp( new InMatchExpression() );
  589. // Status s = temp->init( name );
  590. // if ( !s.isOK() )
  591. // return StatusWithMatchExpression( s );
  592. // s = _parseArrayFilterEntries( temp->getArrayFilterEntries(), e.Obj() );
  593. // if ( !s.isOK() )
  594. // return StatusWithMatchExpression( s );
  595. //
  596. // std::auto_ptr<NotMatchExpression> temp2( new NotMatchExpression() );
  597. // s = temp2->init( temp.release() );
  598. // if ( !s.isOK() )
  599. // return StatusWithMatchExpression( s );
  600. //
  601. // return StatusWithMatchExpression( temp2.release() );
  602. // }
  603. //
  604. // case BSONObj::opSIZE: {
  605. // int size = 0;
  606. // if ( e.type() == String ) {
  607. // // matching old odd semantics
  608. // size = 0;
  609. // }
  610. // else if ( e.type() == NumberInt || e.type() == NumberLong ) {
  611. // size = e.numberInt();
  612. // }
  613. // else if ( e.type() == NumberDouble ) {
  614. // if ( e.numberInt() == e.numberDouble() ) {
  615. // size = e.numberInt();
  616. // }
  617. // else {
  618. // // old semantcs require exact numeric match
  619. // // so [1,2] != 1 or 2
  620. // size = -1;
  621. // }
  622. // }
  623. // else {
  624. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$size needs a number" );
  625. // }
  626. //
  627. // std::auto_ptr<SizeMatchExpression> temp( new SizeMatchExpression() );
  628. // Status s = temp->init( name, size );
  629. // if ( !s.isOK() )
  630. // return StatusWithMatchExpression( s );
  631. // return StatusWithMatchExpression( temp.release() );
  632. // }
  633. //
  634. // case BSONObj::opEXISTS: {
  635. // if ( e.eoo() )
  636. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$exists can't be eoo" );
  637. // std::auto_ptr<ExistsMatchExpression> temp( new ExistsMatchExpression() );
  638. // Status s = temp->init( name );
  639. // if ( !s.isOK() )
  640. // return StatusWithMatchExpression( s );
  641. // if ( e.trueValue() )
  642. // return StatusWithMatchExpression( temp.release() );
  643. // std::auto_ptr<NotMatchExpression> temp2( new NotMatchExpression() );
  644. // s = temp2->init( temp.release() );
  645. // if ( !s.isOK() )
  646. // return StatusWithMatchExpression( s );
  647. // return StatusWithMatchExpression( temp2.release() );
  648. // }
  649. //
  650. // case BSONObj::opTYPE: {
  651. // if ( !e.isNumber() )
  652. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$type has to be a number" );
  653. // int type = e.numberInt();
  654. // if ( e.type() != NumberInt && type != e.number() )
  655. // type = -1;
  656. // std::auto_ptr<TypeMatchExpression> temp( new TypeMatchExpression() );
  657. // Status s = temp->init( name, type );
  658. // if ( !s.isOK() )
  659. // return StatusWithMatchExpression( s );
  660. // return StatusWithMatchExpression( temp.release() );
  661. // }
  662. //
  663. //
  664. // case BSONObj::opMOD:
  665. // return _parseMOD( name, e );
  666. //
  667. // case BSONObj::opOPTIONS: {
  668. // // TODO: try to optimize this
  669. // // we have to do this since $options can be before or after a $regex
  670. // // but we validate here
  671. // BSONObjIterator i( context );
  672. // while ( i.more() ) {
  673. // BSONElement temp = i.next();
  674. // if ( temp.getGtLtOp( -1 ) == BSONObj::opREGEX )
  675. // return StatusWithMatchExpression( NULL );
  676. // }
  677. //
  678. // return StatusWithMatchExpression( ErrorCodes::BadValue, "$options needs a $regex" );
  679. // }
  680. //
  681. // case BSONObj::opREGEX: {
  682. // return _parseRegexDocument( name, context );
  683. // }
  684. //
  685. // case BSONObj::opELEM_MATCH:
  686. // return _parseElemMatch( name, e );
  687. //
  688. // case BSONObj::opALL:
  689. // return _parseAll( name, e );
  690. //
  691. // case BSONObj::opWITHIN:
  692. // case BSONObj::opGEO_INTERSECTS:
  693. // case BSONObj::opNEAR:
  694. // return expressionParserGeoCallback( name, x, context );
  695. //
  696. // }
  697. //
  698. // return StatusWithMatchExpression( ErrorCodes::BadValue,
  699. // mongoutils::str::stream() << "not handled: " << e.fieldName() );
  700. // }
  701. }
  702. /**
  703. *
  704. * This documentation was automatically generated. Please update when you touch this function.
  705. * @method _parseTreeList
  706. * @param
  707. *
  708. */
  709. proto._parseTreeList = function _parseTreeList( /* const BSONObj& arr, ListOfMatchExpression* out */ ){
  710. // File: expression_parser_tree.cpp lines: 33-52
  711. // Status MatchExpressionParser::_parseTreeList( const BSONObj& arr, ListOfMatchExpression* out ) {
  712. // if ( arr.isEmpty() )
  713. // return Status( ErrorCodes::BadValue,
  714. // "$and/$or/$nor must be a nonempty array" );
  715. //
  716. // BSONObjIterator i( arr );
  717. // while ( i.more() ) {
  718. // BSONElement e = i.next();
  719. //
  720. // if ( e.type() != Object )
  721. // return Status( ErrorCodes::BadValue,
  722. // "$or/$and/$nor entries need to be full objects" );
  723. //
  724. // StatusWithMatchExpression sub = _parse( e.Obj(), false );
  725. // if ( !sub.isOK() )
  726. // return sub.getStatus();
  727. //
  728. // out->add( sub.getValue() );
  729. // }
  730. // return Status::OK();
  731. // }
  732. }
  733. /**
  734. *
  735. * This documentation was automatically generated. Please update when you touch this function.
  736. * @method parse
  737. * @param
  738. *
  739. */
  740. proto.parse = function parse( /* const BSONObj& obj */ ){
  741. // File: expression_parser.h lines: 40-41
  742. // static StatusWithMatchExpression parse( const BSONObj& obj ) {
  743. // return _parse( obj, true );
  744. // }
  745. }