Как использовать renameCollection с помощью Meteor? Я хотел бы сделать это внутри Meteor, потому что мне нужно делать миграции для среды разработки и производства.renameCollection with Meteor
1
A
ответ
0
Используйте RemoteCollectionDriver для доступа к собственному драйверу mongo и командам администратора экземпляра, включая команду renameCollection
.
Следующий пример переименовывает коллекцию с именем заказов в базе данных test
к orders2016
в базе данных test
:
var mongoDriver = MongoInternals.defaultRemoteCollectionDriver(), // or Meteor._RemoteCollectionDriver
db = mongoDriver.mongo.db;
// for commands not natively supported by the driver - https://docs.mongodb.org/manual/reference/command/
db.command({ renameCollection: "test.orders", to: "test.orders2016" }, function(error, result) {
if (error) throw error;
if (result.errmsg) {
console.error('Error calling native renameCollection command:', result.errmsg);
}
else {
console.log(result);
}
});
Для реализации этой стороны сервера, вы могли бы следовать этой асинхронной схеме:
var shell = function() {
var Future = Npm.require('fibers/future'),
future = new Future(),
db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
db.command({ renameCollection: "test.orders", to: "test.orders2016" },
function(error, result) {
if (err) throw new Meteor.Error(500, "failed");
future.return(result);
}
);
return future.wait();
};
Смежные вопросы
- 1. Pagination with meteor
- 2. Dynamic SVG with Meteor
- 3. Box2d-Web with Meteor
- 4. Meteor build with settings.json
- 5. Gridster add_widget with Meteor
- 6. HTML (5) with meteor
- 7. Meteor: loop with counter
- 8. Meteor upsert with mongo
- 9. Err_connection_refused with meteor uploads
- 10. Использование Joose with Meteor
- 11. Swiper with Meteor
- 12. Bootstrap Carousel with Meteor
- 13. Meteor with DataTables: Meteor._atFlush TypeError
- 14. Использование summernote with meteor (Discover Meteor)
- 15. Meteor UI helper with Meteor.users
- 16. Использование jquery-layout with meteor
- 17. GRIDFS mp3 Collection with meteor
- 18. Bourbon and Neat with Meteor
- 19. meteor-with-angular tutorial: dependenciesproblem
- 20. Vulcanize with polymer in meteor
- 21. Meteor - Autoform with Meteor.users collection
- 22. Использование intern js with meteor
- 23. Зачем использовать Bower with Meteor?
- 24. upload with meteor and dropbox
- 25. Jquery multi select plugin with meteor
- 26. Pixijs with Meteor получает черное полотно
- 27. Объяснить использование {{#with}} в meteor JS
- 28. Meteor 1.0: Upsert with Mongo Selector
- 29. Pay with Stripe или Braintree в Meteor
- 30. Что такое this.props (Meteor with React Tutorial)
You может использовать драйвер Node.js MongoDB, но я предполагаю, что будут побочные эффекты при использовании на запущенном сервере Meteor (с хвостовиком и реактивностью OpLog). Что вы пытаетесь достичь? – MasterAM
Возможный дубликат [Как переименовать коллекцию в метеор?] (Http://stackoverflow.com/questions/29070599/how-to-rename-a-collection-in-meteor) –