diff options
Diffstat (limited to 'src/mongo/db/field_parser.cpp')
-rw-r--r-- | src/mongo/db/field_parser.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/db/field_parser.cpp b/src/mongo/db/field_parser.cpp index 0ce90b95e9a..7a3a61b3203 100644 --- a/src/mongo/db/field_parser.cpp +++ b/src/mongo/db/field_parser.cpp @@ -283,4 +283,28 @@ namespace mongo { return FIELD_INVALID; } + FieldParser::FieldState FieldParser::extractID( BSONObj doc, + const BSONField<BSONObj>& field, + BSONObj* out, + string* errMsg ) { + BSONElement elem = doc[field.name()]; + if (elem.eoo()) { + if (field.hasDefault()) { + *out = field.getDefault().firstElement().wrap( "" ); + return FIELD_DEFAULT; + } + else { + return FIELD_NONE; + } + } + + if ( elem.type() != Array ) { + *out = elem.wrap( "" ).getOwned(); + return FIELD_SET; + } + + _genFieldErrMsg(doc, field, "id", errMsg); + return FIELD_INVALID; + } + } // namespace mongo |