コード例 #1
0
    intrusive_ptr<Document> DocumentSourceProject::getCurrent() {
        intrusive_ptr<Document> pInDocument(pSource->getCurrent());

        /* create the result document */
        const size_t sizeHint =
            pEO->getSizeHint(pInDocument) + (excludeId ? 0 : 1);
        intrusive_ptr<Document> pResultDocument(Document::create(sizeHint));

        if (!excludeId) {
            intrusive_ptr<const Value> pId(
                pInDocument->getField(Document::idName));

            /*
              Previous projections could have removed _id, (or declined to
              generate it) so it might already not exist.  Only attempt to add
              if we found it.
            */
            if (pId.get())
                pResultDocument->addField(Document::idName, pId);
        }

        /*
          Use the ExpressionObject to create the base result.

          If we're excluding fields at the top level, leave out the _id if
          it is found, because we took care of it above.
        */
        pEO->addToDocument(pResultDocument, pInDocument, true);

        return pResultDocument;
    }
コード例 #2
0
    intrusive_ptr<Document> DocumentSourceProject::getCurrent() {
	intrusive_ptr<Document> pInDocument(pSource->getCurrent());

	/* create the result document */
	const size_t sizeHint =
	    pEO->getSizeHint(pInDocument) + (excludeId ? 0 : 1);
	intrusive_ptr<Document> pResultDocument(Document::create(sizeHint));

	if (!excludeId) {
	    intrusive_ptr<const Value> pId(
		pInDocument->getField(Document::idName));
	    pResultDocument->addField(Document::idName, pId);
	}

	/* use the ExpressionObject to create the base result */
	pEO->addToDocument(pResultDocument, pInDocument);

        return pResultDocument;
    }
コード例 #3
0
    intrusive_ptr<Document> DocumentSourceProject::getCurrent() {
        intrusive_ptr<Document> pInDocument(pSource->getCurrent());

        /* create the result document */
        const size_t sizeHint = pEO->getSizeHint();
        intrusive_ptr<Document> pResultDocument(Document::create(sizeHint));

        /*
          Use the ExpressionObject to create the base result.

          If we're excluding fields at the top level, leave out the _id if
          it is found, because we took care of it above.
        */
        pEO->addToDocument(pResultDocument, pInDocument, /*root=*/pInDocument);

#if defined(_DEBUG)
        if (!_simpleProjection.getSpec().isEmpty()) {
            // Make sure we return the same results as Projection class

            BSONObjBuilder inputBuilder;
            pSource->getCurrent()->toBson(&inputBuilder);
            BSONObj input = inputBuilder.done();

            BSONObjBuilder outputBuilder;
            pResultDocument->toBson(&outputBuilder);
            BSONObj output = outputBuilder.done();

            BSONObj projected = _simpleProjection.transform(input);

            if (projected != output) {
                log() << "$project applied incorrectly: " << getRaw() << endl;
                log() << "input:  " << input << endl;
                log() << "out: " << output << endl;
                log() << "projected: " << projected << endl;
                verify(false); // exits in _DEBUG builds
            }
        }
#endif

        return pResultDocument;
    }