当前位置: 首页>>代码示例>>C++>>正文


C++ NamespaceDetails::ensureIndex方法代码示例

本文整理汇总了C++中NamespaceDetails::ensureIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ NamespaceDetails::ensureIndex方法的具体用法?C++ NamespaceDetails::ensureIndex怎么用?C++ NamespaceDetails::ensureIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NamespaceDetails的用法示例。


在下文中一共展示了NamespaceDetails::ensureIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runInsertFromOplog

    static void runInsertFromOplog(const char* ns, BSONObj op) {
        BSONObj row = op[KEY_STR_ROW].Obj();
        // handle add index case
        if (mongoutils::str::endsWith(ns, ".system.indexes")) {
            // do not build the index if the user has disabled
            if (theReplSet->buildIndexes()) {
                Client::WriteContext ctx(ns);
                NamespaceDetails* nsd = nsdetails(ns);
                const string &coll = row["ns"].String();

                NamespaceDetails* collNsd = nsdetails(coll);
                const bool ok = collNsd->ensureIndex(row);
                if (!ok) {
                    // the index already exists, so this is a no-op
                    // Note that for create index and drop index, we
                    // are tolerant of the fact that the operation may
                    // have already been done
                    return;
                }
                // overwrite set to true because we are running on a secondary
                insertOneObject(nsd, row, NamespaceDetails::NO_UNIQUE_CHECKS);
            }
        }
        else {
            try {
                Client::ReadContext ctx(ns);
                runNonSystemInsertFromOplogWithLock(ns, row);
            }
            catch (RetryWithWriteLock &e) {
                Client::WriteContext ctx(ns);
                runNonSystemInsertFromOplogWithLock(ns, row);
            }
        }
    }
开发者ID:lucciano,项目名称:mongo-1,代码行数:34,代码来源:oplog_helpers.cpp

示例2: insertObjects

    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);
    }
开发者ID:aberg001,项目名称:mongo,代码行数:29,代码来源:insert.cpp


注:本文中的NamespaceDetails::ensureIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。