void insertObjects(const char *ns, const vector<BSONObj> &objs, bool keepGoing, uint64_t flags, bool logop ) { StringData _ns(ns); if (NamespaceString::isSystem(_ns)) { massert(16748, "need transaction to run insertObjects", cc().txnStackSize() > 0); uassert(10095, "attempt to insert in reserved database name 'system'", nsToDatabaseSubstring(_ns) != "system"); massert(16750, "attempted to insert multiple objects into a system namspace at once", objs.size() == 1); // Trying to insert into a system collection. Fancy side-effects go here: if (nsToCollectionSubstring(ns) == "system.indexes") { BSONObj obj = stripDropDups(objs[0]); NamespaceDetails *d = getAndMaybeCreateNS(obj["ns"].Stringdata(), logop); bool ok = d->ensureIndex(obj); if (!ok) { // Already had that index return; } // Now we have to actually insert that document into system.indexes, we may have // modified it with stripDropDups. vector<BSONObj> newObjs; newObjs.push_back(obj); _insertObjects(ns, newObjs, keepGoing, flags, logop); return; } else if (!legalClientSystemNS(ns, true)) { uasserted(16459, str::stream() << "attempt to insert in system namespace '" << ns << "'"); } } _insertObjects(ns, objs, keepGoing, flags, logop); }
IndexDetails::IndexDetails(const BSONObj &info) : _info(stripDropDups(info)), _keyPattern(info["key"].Obj().copy()), _unique(info["unique"].trueValue()), _sparse(info["sparse"].trueValue()), _clustering(info["clustering"].trueValue()) { verify(!_info.isEmpty()); verify(!_keyPattern.isEmpty()); }
IndexDetails::IndexDetails(const BSONObj &info) : _info(stripDropDups(info)), _keyPattern(info["key"].Obj().copy()), _unique(info["unique"].trueValue()), _sparse(info["sparse"].trueValue()), _clustering(info["clustering"].trueValue()) { verify(!_info.isEmpty()); verify(!_keyPattern.isEmpty()); if (isIdIndex() && !unique()) { uasserted(17365, "_id index cannot be non-unique"); } }