|
@@ -0,0 +1,32 @@
|
|
|
|
|
+import mongoose from "mongoose"; // 导入 mongoose 和 Connection 用于处理远程连接
|
|
|
|
|
+import Art from "../../src/models/artModel"; // 👈 导入 Art 模型和 IArt 接口
|
|
|
|
|
+
|
|
|
|
|
+// 远程数据库连接 URL
|
|
|
|
|
+const REMOTE_MONGO_URI = "mongodb://coloring:coloring123.@hk.jccytech.cn:7881/?authSource=admin";
|
|
|
|
|
+
|
|
|
|
|
+async function test() {
|
|
|
|
|
+ let remoteConn = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 建立远程数据库连接和模型
|
|
|
|
|
+ remoteConn = await mongoose.createConnection(REMOTE_MONGO_URI);
|
|
|
|
|
+ const RemoteArt = remoteConn.model < IArt > ("Art", Art.schema);
|
|
|
|
|
+ console.log(`Connected to remote database.`);
|
|
|
|
|
+
|
|
|
|
|
+ const remoteArtDoc = await RemoteArt.findById(artworkId);
|
|
|
|
|
+ if (remoteArtDoc) {
|
|
|
|
|
+ console.log(remoteArtDoc);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.warn(`Remote Art document with ID ${artworkId} not found. Skipping remote update.`);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error(error);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ if (remoteConn) {
|
|
|
|
|
+ await remoteConn.close();
|
|
|
|
|
+ console.log("Disconnected from remote database.");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+test();
|