Текстовый указатель в MongoDB - PullRequest
0 голосов
/ 03 октября 2018

У нас есть индекс Text , созданный на нашей MongoDb.

Нам нужно написать скрипт index (Text) .

Примечание: 1. Я попытался и не получил текстовый индекс.

   2. db.getIndexes() is not showing text index.

1 Ответ

0 голосов
/ 03 октября 2018

у меня это работало в оболочке монго (v4.0.0):

db.getCollectionInfos().forEach(function(coll) {
  if (coll.type === "collection" ) {
    db[coll.name].getIndexes().forEach(function(index) {
      if ("id" !== index.name) {
        var indexKey = index.key
        delete index.v
        delete index.key
        index.background = true // optional: force background to be true
        print("db." + coll.name + ".createIndex(" + JSON.stringify(indexKey) + ", " + JSON.stringify(index) + ")");
      }
    });
  }
});

и как один лайнер ...

db.getCollectionInfos().forEach(function(coll) { if (coll.type === "collection" ) { db[coll.name].getIndexes().forEach(function(index) { if ("id" !== index.name) { var indexKey = index.key delete index.v delete index.key index.background = true print("db." + coll.name + ".createIndex(" + JSON.stringify(indexKey) + ", " + JSON.stringify(index) + ")"); } }); } });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...