【发布时间】:2020-07-19 23:26:10
【问题描述】:
我有两个数据库,我想从集合中的另一个数据库写入数据。
我连接到一个 mongoDB
mongoose.connect("mongodb://XXX:YYY@localhost:27017/realtime?authSource=admin"
并根据我当前使用的模型写入集合。
我需要一个键值对(它是一个时间戳)来自另一个运行在同一端口 mongodb://XXX:YYY@localhost:27017/timetable?authSource=admin 上的不同数据库。
这是一个sn-p,希望对你有帮助。
EntityModel
.find({})
.limit(10)
.then((entities) => {
entities.forEach((entity) => {
// this is where I need to access the other DB
// to get arrivalTimetable from the timetable database for Each entity
tripData.stops.push({
stop_id: stu.stopId,
arrivalTimetable: arrivalTimetable,
arrivalRealtime: arrivalRT
});
const tripDelay = new TripDelay(tripData);
trip.save();
}
有什么好的方法,获取所需的数据并将其保存到当前集合中?
【问题讨论】:
标签: mongodb mongoose multiple-databases