/ MakeCursor: make the cursor used to retrieve documents. */ /
| 352 | /* MakeCursor: make the cursor used to retrieve documents. */ |
| 353 | /***********************************************************************/ |
| 354 | bool CMgoConn::MakeCursor(PGLOBAL g) |
| 355 | { |
| 356 | const char *p; |
| 357 | bool id, all = false; |
| 358 | PCSZ options = Pcg->Options; |
| 359 | PTDB tp = Pcg->Tdbp; |
| 360 | PCOL cp; |
| 361 | PSTRG s = NULL; |
| 362 | PFIL filp = tp->GetFilter(); |
| 363 | |
| 364 | id = (tp->GetMode() == MODE_UPDATE || tp->GetMode() == MODE_DELETE); |
| 365 | |
| 366 | if (options && !stricmp(options, "all")) { |
| 367 | options = NULL; |
| 368 | all = true; |
| 369 | } else for (cp = tp->GetColumns(); cp && !all; cp = cp->GetNext()) |
| 370 | if (cp->GetFmt() && !strcmp(cp->GetFmt(), "*") && !options) |
| 371 | all = true; |
| 372 | else if (!id) |
| 373 | id = !strcmp(cp->GetFmt() ? cp->GetFmt() : cp->GetName(), "_id"); |
| 374 | |
| 375 | if (Pcg->Pipe) { |
| 376 | if (trace(1)) |
| 377 | htrc("Pipeline: %s\n", options); |
| 378 | |
| 379 | p = strrchr(options, ']'); |
| 380 | |
| 381 | if (!p) { |
| 382 | snprintf(g->Message, sizeof(g->Message), "Missing ] in pipeline"); |
| 383 | return true; |
| 384 | } else |
| 385 | *(char*)p = 0; |
| 386 | |
| 387 | s = new(g) STRING(g, 1023, (PSZ)options); |
| 388 | |
| 389 | if (filp) { |
| 390 | s->Append(",{\"$match\":"); |
| 391 | |
| 392 | if (MakeSelector(g, filp, s)) { |
| 393 | snprintf(g->Message, sizeof(g->Message), "Failed making selector"); |
| 394 | return true; |
| 395 | } else |
| 396 | s->Append('}'); |
| 397 | |
| 398 | tp->SetFilter(NULL); // Not needed anymore |
| 399 | } // endif To_Filter |
| 400 | |
| 401 | if (tp->GetColumns() && !strstr(s->GetStr(), "$project")) { |
| 402 | // Project list |
| 403 | s->Append(",{\"$project\":{\""); |
| 404 | |
| 405 | if (!id) |
| 406 | s->Append("_id\":0,\""); |
| 407 | |
| 408 | Project(g, s); |
| 409 | s->Append("}}"); |
| 410 | } // endif all |
| 411 |
no test coverage detected