void CursorResponse::addToBSON(CursorResponse::ResponseType responseType, BSONObjBuilder* builder) const { BSONObjBuilder cursorBuilder(builder->subobjStart(kCursorField)); cursorBuilder.append(kIdField, _cursorId); cursorBuilder.append(kNsField, _nss.ns()); const char* batchFieldName = (responseType == ResponseType::InitialResponse) ? kBatchFieldInitial : kBatchField; BSONArrayBuilder batchBuilder(cursorBuilder.subarrayStart(batchFieldName)); for (const BSONObj& obj : _batch) { batchBuilder.append(obj); } batchBuilder.doneFast(); cursorBuilder.doneFast(); if (_latestOplogTimestamp) { builder->append(kInternalLatestOplogTimestampField, *_latestOplogTimestamp); } builder->append("ok", 1.0); if (_writeConcernError) { builder->append("writeConcernError", *_writeConcernError); } }
void CursorResponse::addToBSON(CursorResponse::ResponseType responseType, BSONObjBuilder* builder) const { BSONObjBuilder cursorBuilder(builder->subobjStart(kCursorField)); cursorBuilder.append(kIdField, _cursorId); cursorBuilder.append(kNsField, _nss.ns()); const char* batchFieldName = (responseType == ResponseType::InitialResponse) ? kBatchFieldInitial : kBatchField; BSONArrayBuilder batchBuilder(cursorBuilder.subarrayStart(batchFieldName)); for (const BSONObj& obj : _batch) { batchBuilder.append(obj); } batchBuilder.doneFast(); cursorBuilder.doneFast(); builder->append("ok", 1.0); }